How do I get started in C using avr-gcc on the mega2560
Try leveraging the existing Arduino library. Arduino.h and wiring_digital.c are of particular note here and implement the functions you were originally using.