Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2011
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.18 KB | None | 0 0
  1.  
  2.  
  3. #include <avr/io.h>
  4. #include "lcd.h" // final transmitter wont need this.
  5.  
  6. char values[4];
  7.  
  8. void initKeyboard() {
  9.   DDRB = 0x07;  
  10. }
  11.  
  12. int scanKeyboard() {  
  13.  
  14.   PORTB = 0x06 | 0xF8; // first row low, pullups on
  15.   lcd_delay(1);
  16.   if ((PINB | 0x07) != 0xFF) {
  17.     return PINB;
  18.   }
  19.  
  20.   PORTB = 0x05 | 0xF8; // second row low, pullups on
  21.   lcd_delay(1);
  22.   if ((PINB | 0x07) != 0xFF) {
  23.     return PINB;
  24.   }
  25.  
  26.   PORTB = 0x03 | 0xF8; // third row low, pullups on
  27.   lcd_delay(1);
  28.   if ((PINB | 0x07) != 0xFF) {
  29.     return PINB;
  30.   }
  31.  
  32.   return 0;
  33.    
  34. }
  35.  
  36. void Menu(unsigned char command) {
  37.   static char state;
  38.   char ostate;
  39.  
  40.   ostate = state;
  41.  
  42.   if (0) {
  43.   } else if (command == 0x00) {  state = 0;                      // reset request
  44.   } else if ((command == 189) && (state < 2))  {  state++;       // down
  45.   } else if ((command == 221) && (state > 0)) { state --;        // up
  46.   } else if ((command == 235)) { values[state]++; ostate = 127;  // right
  47.   } else if ((command == 238)) { values[state]--; ostate = 127;  // left
  48.   }
  49.  
  50.   if (ostate == state) {
  51.     return;
  52.   } else if (state == 0) {   // default menu
  53.     lcd_cls();
  54.     lcd_goto(0x00); lcd_putstr("Opt A:");
  55.     lcd_goto(0x40); lcd_putstr("Value "); print5(values[0]);
  56.   } else if (state == 1) {   // default menu
  57.     lcd_cls();
  58.     lcd_goto(0x00); lcd_putstr("Opt B:");
  59.     lcd_goto(0x40); lcd_putstr("Value "); print5(values[1]);
  60.   } else if (state == 2) {   // default menu
  61.     lcd_cls();
  62.     lcd_goto(0x00); lcd_putstr("Opt C:");
  63.     lcd_goto(0x40); lcd_putstr("Value "); print5(values[2]);
  64.   }
  65.    
  66.  // lcd_goto(0x00);   print5(state);
  67.  
  68. }
  69.  
  70.  
  71. int main(void) {  
  72.    
  73.    int a;
  74.    
  75.     lcd_init();
  76.     initKeyboard();
  77.  
  78.    
  79.     lcd_control(1,0,0);  
  80.     lcd_cls();
  81.    
  82.     // lcd_home();
  83.    /*
  84.     lcd_putch(0x7E);
  85.     lcd_putch(0x7F);
  86.     lcd_putch(0x5E);
  87.     lcd_putch(0x76);
  88.    
  89.     lcd_goto(0x40);
  90.     lcd_putstr("take me apart :)");
  91. */
  92.  
  93.   while(1)  {
  94.     a = scanKeyboard();
  95.     if (a != 0) {        
  96.       Menu(a);  
  97.     }
  98.     if (a == 246) {
  99.        Menu(0);
  100.     }
  101.     while(scanKeyboard() != 0);
  102.     lcd_delay(1000);
  103.   }
  104.  
  105.  
  106.     return 0;
  107. }
  108.  
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement