- #include <mega32.h>
- #include <alcd.h>
- #include <delay.h>
- #include <stdio.h>
- ///////////////////////////////
- #define led_DDR 0b00001111
- #define led_1 0b00000001
- #define led_2 0b00000010
- #define led_3 0b00000100
- #define led_4 0b00001000
- #define led_off 0b00000000
- /////////////////////////////
- #define button_P 0b00000011
- /////////////////////////////
- const unsigned char digit[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f} ;
- enum Order{
- main_menu,
- active,
- } ;
- void main(void)
- {
- int t_b1=0 , t_b2=0; // Button Timing
- unsigned int select = 1;
- char str[16];
- enum Order Menu;
- // Alphanumeric LCD initialization
- // Connections are specified in the
- // Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
- // RS - PORTA Bit 0
- // RD - PORTA Bit 1
- // EN - PORTA Bit 2
- // D4 - PORTA Bit 4
- // D5 - PORTA Bit 5
- // D6 - PORTA Bit 6
- // D7 - PORTA Bit 7
- // Characters/line: 16
- lcd_init(16);
- DDRB = 0x00;
- PORTB = button_P;
- DDRC = led_DDR;
- DDRD = 0xff;
- Menu = main_menu;
- while (1)
- {
- /////////////////////timing
- delay_ms(1);
- t_b1 ++;
- t_b2 ++;
- ////////////////////timing
- switch (Menu)
- {
- //////////////////////////////////////////////////////////main Menu
- case main_menu:
- if(select <= 2) /////main Menu graphic
- {
- lcd_gotoxy(0,0);
- lcd_puts("Led-1");
- lcd_gotoxy(0,1);
- lcd_puts("Led-2");
- }
- else if(select <= 4)
- {
- lcd_gotoxy(0,0);
- lcd_puts("Led-3");
- lcd_gotoxy(0,1);
- lcd_puts("Led-4");
- }
- else
- select = 1 ;
- switch (select)
- {
- case 1:
- lcd_gotoxy(13,0);
- lcd_puts("<=");
- break;
- case 2:
- lcd_gotoxy(13,1);
- lcd_puts("<=");
- break;
- case 3:
- lcd_gotoxy(13,0);
- lcd_puts("<=");
- break;
- case 4:
- lcd_gotoxy(13,1);
- lcd_puts("<=");
- break;
- }
- /////////main Menu graphic
- if( (PINB & 1 ) == 0 && t_b1 > 199 ) /////// Select Button
- {
- select ++ ;
- lcd_clear();
- t_b1 = 0;
- }
- if( (PINB & 2 ) == 0 && t_b2 > 199 ) //////Enter Button
- {
- Menu = active;
- lcd_clear();
- t_b2 = 0;
- }
- //////defalt settings
- PORTD = 0x40 ;
- PORTC = 0x00 ;
- break;
- //////////////////////////////////////////////////////////end main Menu
- ///////////////////////////////////////////////////////////Activate
- case active:
- PORTD = digit[select];
- switch (select)
- {
- case 1:
- PORTC = 0x01;
- break;
- case 2:
- PORTC = 0x02;
- break;
- case 3:
- PORTC = 0x04;
- break;
- case 4:
- PORTC = 0x08;
- break;
- }
- lcd_gotoxy(0,0);
- lcd_puts(str);
- if( (PINB & 2 ) == 0 && t_b2 > 199 ) //////back Button
- {
- Menu = main_menu;
- lcd_clear();
- t_b2 = 0;
- }
- break;
- ////////////////////////////////////////////////////end Activate
- }
- }
- }
Recent Pastes