Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <util/delay.h>
- #define F_CPU 1600000UL
- #define RS 6
- #define E 5
- void send_a_command (unsigned char command);
- void send_a_character(unsigned char character);
- void send_a_number(int a);
- void send_a_string(char *a);
- void avr_setup(void)
- {
- DDRA = 0xFF; //all outputs
- DDRB = 0x00; //PORTB input for buttons
- PORTB = 0xFF; //pullups all on
- DDRA = 0xFF;
- DDRD = 0xFF;
- }
- int main(void)
- {
- int a=0;
- int b=0;
- int c=0;
- int d=0;
- _delay_ms(50);
- send_a_command(0x01);// sending all clear command
- send_a_command(0x38);// 16*2 line LCD
- send_a_command(0x0E);// screen and cursor ON
- print_screen(a%10,b%10,c%10,d%10);// printing 4 digits
- avr_setup();
- while(1)
- {
- _delay_ms(1000);
- if (!(PINB & (1<<PB0)))
- {
- a +=1;
- print_screen(a%10,b%10,c%10,d%10);
- }
- if (!(PINB & (1<<PB1)))
- {
- b +=1;
- print_screen(a%10,b%10,c%10,d%10);
- }
- if (!(PINB & (1<<PB2)))
- {
- c +=1;
- print_screen(a%10,b%10,c%10,d%10);
- }
- if (!(PINB & (1<<PB3)))
- {
- d +=1;
- print_screen(a%10,b%10,c%10,d%10);
- }
- if(a%10==1&&b%10==2&&c%10==3&&d%10==4)
- {
- send_a_command(0x01);
- send_a_string("Open");
- }
- }
- }
- void send_a_string(char *a)
- {
- for (int i=0;a[i]!='\0';i++)
- {
- send_a_character(a[i]);
- }
- }
- void send_a_command (unsigned char command)
- {
- PORTA=command;
- PORTD&= ~(1<<RS);
- PORTD|= (1<<E);
- _delay_ms(50);
- PORTD&= ~(1<<E);
- PORTA =0;
- }
- void send_a_number(int a)
- {
- char character = a + '0';
- PORTA=character;
- PORTD|= (1<<RS);
- PORTD|= (1<<E);
- _delay_ms(50);
- PORTD&= ~(1<<E);
- PORTA =0;
- }
- void send_a_character (unsigned char character)
- {
- PORTA=character;
- PORTD|= (1<<RS);
- PORTD|= (1<<E);
- _delay_ms(50);
- PORTD&= ~(1<<E);
- PORTA =0;
- }
- void send_a_result(int a,int b,int c,int d)
- {
- char aa=a+'0';
- char bb=b+'0';
- char cc=c+'0';
- char dd=d+'0';
- char result[4]= { aa,bb,cc,dd, };
- send_a_string(result);
- }
- void print_screen(int a,int b,int c,int d)
- {
- send_a_command(0x01);// sending all clear command
- send_a_string("Enter Code:");
- send_a_result( a, b, c, d);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement