SHARE
TWEET

Untitled

a guest Jan 23rd, 2020 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <avr/io.h>
  2. #include <util/delay.h>
  3.  
  4.  
  5. #define F_CPU 1600000UL
  6. #define RS 6
  7. #define E  5
  8.  
  9. void send_a_command (unsigned char command);
  10. void send_a_character(unsigned char character);
  11. void send_a_number(int a);
  12. void send_a_string(char *a);
  13.  
  14.  
  15.  
  16. void avr_setup(void)
  17. {
  18.     DDRA = 0xFF;    //all outputs
  19.     DDRB = 0x00;    //PORTB input for buttons
  20.     PORTB = 0xFF;   //pullups all on
  21.     DDRA = 0xFF;
  22.     DDRD = 0xFF;
  23. }
  24.  
  25.  
  26. int main(void)
  27. {
  28.     int a=0;
  29.     int b=0;
  30.     int c=0;
  31.     int d=0;
  32.     _delay_ms(50);
  33.     send_a_command(0x01);// sending all clear command
  34.     send_a_command(0x38);// 16*2 line LCD
  35.     send_a_command(0x0E);// screen and cursor ON
  36.     print_screen(a%10,b%10,c%10,d%10);// printing 4 digits
  37.     avr_setup();
  38.  
  39.  while(1)
  40.     {
  41.         _delay_ms(1000);
  42.         if (!(PINB & (1<<PB0)))
  43.         {
  44.             a +=1;
  45.             print_screen(a%10,b%10,c%10,d%10);
  46.         }
  47.         if (!(PINB & (1<<PB1)))
  48.         {
  49.             b +=1;
  50.             print_screen(a%10,b%10,c%10,d%10);
  51.         }
  52.         if (!(PINB & (1<<PB2)))
  53.         {
  54.             c +=1;
  55.             print_screen(a%10,b%10,c%10,d%10);
  56.         }
  57.         if (!(PINB & (1<<PB3)))
  58.         {
  59.             d +=1;
  60.             print_screen(a%10,b%10,c%10,d%10);
  61.         }
  62.         if(a%10==1&&b%10==2&&c%10==3&&d%10==4)
  63.         {
  64.             send_a_command(0x01);
  65.             send_a_string("Open");
  66.         }
  67.     }
  68. }
  69.  
  70. void send_a_string(char *a)
  71. {
  72.     for (int i=0;a[i]!='\0';i++)
  73.     {
  74.         send_a_character(a[i]);
  75.     }
  76. }
  77. void send_a_command (unsigned char command)
  78. {
  79.     PORTA=command;
  80.     PORTD&= ~(1<<RS);
  81.     PORTD|= (1<<E);
  82.     _delay_ms(50);
  83.     PORTD&= ~(1<<E);
  84.     PORTA =0;
  85. }
  86.  
  87. void send_a_number(int a)
  88. {
  89.     char character = a + '0';
  90.     PORTA=character;
  91.     PORTD|= (1<<RS);
  92.     PORTD|= (1<<E);
  93.     _delay_ms(50);
  94.     PORTD&= ~(1<<E);
  95.     PORTA =0;
  96. }
  97.  
  98. void send_a_character (unsigned char character)
  99. {
  100.     PORTA=character;
  101.     PORTD|= (1<<RS);
  102.     PORTD|= (1<<E);
  103.     _delay_ms(50);
  104.     PORTD&= ~(1<<E);
  105.     PORTA =0;
  106. }
  107. void send_a_result(int a,int b,int c,int d)
  108. {
  109.     char aa=a+'0';
  110.     char bb=b+'0';
  111.     char cc=c+'0';
  112.     char dd=d+'0';
  113.    
  114.     char result[4]= { aa,bb,cc,dd, };
  115.     send_a_string(result);
  116. }
  117. void print_screen(int a,int b,int c,int d)
  118. {
  119.     send_a_command(0x01);// sending all clear command
  120.     send_a_string("Enter Code:");
  121.     send_a_result( a, b, c, d);
  122. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top