Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include "lcd.h" // final transmitter wont need this.
- char values[4];
- void initKeyboard() {
- DDRB = 0x07;
- }
- int scanKeyboard() {
- PORTB = 0x06 | 0xF8; // first row low, pullups on
- lcd_delay(1);
- if ((PINB | 0x07) != 0xFF) {
- return PINB;
- }
- PORTB = 0x05 | 0xF8; // second row low, pullups on
- lcd_delay(1);
- if ((PINB | 0x07) != 0xFF) {
- return PINB;
- }
- PORTB = 0x03 | 0xF8; // third row low, pullups on
- lcd_delay(1);
- if ((PINB | 0x07) != 0xFF) {
- return PINB;
- }
- return 0;
- }
- void Menu(unsigned char command) {
- static char state;
- char ostate;
- ostate = state;
- if (0) {
- } else if (command == 0x00) { state = 0; // reset request
- } else if ((command == 189) && (state < 2)) { state++; // down
- } else if ((command == 221) && (state > 0)) { state --; // up
- } else if ((command == 235)) { values[state]++; ostate = 127; // right
- } else if ((command == 238)) { values[state]--; ostate = 127; // left
- }
- if (ostate == state) {
- return;
- } else if (state == 0) { // default menu
- lcd_cls();
- lcd_goto(0x00); lcd_putstr("Opt A:");
- lcd_goto(0x40); lcd_putstr("Value "); print5(values[0]);
- } else if (state == 1) { // default menu
- lcd_cls();
- lcd_goto(0x00); lcd_putstr("Opt B:");
- lcd_goto(0x40); lcd_putstr("Value "); print5(values[1]);
- } else if (state == 2) { // default menu
- lcd_cls();
- lcd_goto(0x00); lcd_putstr("Opt C:");
- lcd_goto(0x40); lcd_putstr("Value "); print5(values[2]);
- }
- // lcd_goto(0x00); print5(state);
- }
- int main(void) {
- int a;
- lcd_init();
- initKeyboard();
- lcd_control(1,0,0);
- lcd_cls();
- // lcd_home();
- /*
- lcd_putch(0x7E);
- lcd_putch(0x7F);
- lcd_putch(0x5E);
- lcd_putch(0x76);
- lcd_goto(0x40);
- lcd_putstr("take me apart :)");
- */
- while(1) {
- a = scanKeyboard();
- if (a != 0) {
- Menu(a);
- }
- if (a == 246) {
- Menu(0);
- }
- while(scanKeyboard() != 0);
- lcd_delay(1000);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement