Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ATmega8, 48, 88, 168, 328
- /Reset PC6|1 28|PC5
- PD0|2 27|PC4
- PD1|3 26|PC3 LCD_RW ( 6)
- PD2|4 25|PC2 LCD_E ( 5)
- PD3|5 24|PC1 LCD_RS ( 3)
- PD4|6 23|PC0
- Vcc|7 22|Gnd
- Gnd|8 21|Aref
- PB6|9 20|AVcc
- PB7|10 19|PB5 SCK LCD_D7 (13)
- PD5|11 18|PB4 MISO LCD_D6 (14)
- PD6|12 17|PB3 MOSI LCD_D5 (11)
- PD7|13 16|PB2 LCD_D4 (12)
- PB0|14 15|PB1
- */
- #define F_CPU 1000000UL // 1 MHz standard clock
- #include <avr/io.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <util/delay.h>
- #include "lcd.h"
- /*
- lcd_printbinary(arg, bits);
- prints a binary number on the LCD
- - arg unsigned integer value to be printed
- - bits number of bits to be printed, leading zeros are printed
- */
- void lcd_printbinary(uintmax_t arg, uint8_t bits)
- {
- int8_t i=bits;
- while (i>0)
- {
- i--;
- if (arg & (1 << i))
- {
- lcd_putc('1');
- }
- else
- {
- lcd_putc('0');
- }
- }
- }
- int main(void)
- {
- lcd_init(LCD_DISP_ON); // initialize LCD
- lcd_clrscr(); // clear screen
- DDRD = 0; // all pins input on port D
- PORTD = 0xff; // all pull-ups active on port D
- while (1)
- {
- _delay_ms(2); // short delay
- lcd_gotoxy(0,0); // start at upper left corner
- lcd_puts("0b"); // leading C-style identifier
- lcd_printbinary(PIND, 8); // print value of PIND
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement