Created
September 12, 2010 23:09
-
-
Save rtanglao/576585 to your computer and use it in GitHub Desktop.
Blink and LED & Display status on LCD display
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // led_blink.c | |
| // for NerdKits with ATmega168 | |
| // [email protected] | |
| // modifications by Roland Tanglao for Mac Serial port in Makefile and | |
| // to display status on LCD | |
| #define F_CPU 14745600 | |
| #include <avr/io.h> | |
| #include <avr/interrupt.h> | |
| #include <avr/pgmspace.h> | |
| #include <inttypes.h> | |
| #include "../libnerdkits/delay.h" | |
| #include "../libnerdkits/lcd.h" | |
| // PIN DEFINITIONS: | |
| // | |
| // PC4 -- LED anode | |
| int main() { | |
| lcd_init(); | |
| FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_WRITE); | |
| lcd_home(); | |
| lcd_write_string(PSTR("Hello LED!")); | |
| // LED as output | |
| DDRC |= (1<<PC4); | |
| // loop keeps looking forever | |
| while(1) { | |
| lcd_home(); | |
| lcd_line_two(); | |
| lcd_write_string(PSTR("LED ON ")); | |
| // turn on LED | |
| PORTC |= (1<<PC4); | |
| //delay for 500 milliseconds to let the light stay on | |
| delay_ms(500); | |
| lcd_home(); | |
| lcd_line_two(); | |
| lcd_write_string(PSTR("LED OFF")); | |
| // turn off LED | |
| PORTC &= ~(1<<PC4); | |
| //delay for 500 milliseconds to let the light stay off | |
| delay_ms(500); | |
| } | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| GCCFLAGS=-g -Os -Wall -mmcu=atmega168 | |
| LINKFLAGS=-Wl,-u,vfprintf -lprintf_flt -Wl,-u,vfscanf -lscanf_flt -lm | |
| AVRDUDEFLAGS=-c avr109 -p m168 -b 115200 -P /dev/cu.PL2303-00001004 | |
| LINKOBJECTS=../libnerdkits/delay.o ../libnerdkits/lcd.o ../libnerdkits/uart.o | |
| all: led_blink-upload | |
| led_blink.hex: led_blink.c | |
| make -C ../libnerdkits | |
| avr-gcc ${GCCFLAGS} ${LINKFLAGS} -o led_blink.o led_blink.c ${LINKOBJECTS} | |
| avr-objcopy -j .text -O ihex led_blink.o led_blink.hex | |
| led_blink.ass: led_blink.hex | |
| avr-objdump -S -d led_blink.o > led_blink.ass | |
| led_blink-upload: led_blink.hex | |
| avrdude ${AVRDUDEFLAGS} -U flash:w:led_blink.hex:a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment