/********************************************* This program was produced by the CodeWizardAVR V1.0.1.5d Standard Automatic Program Generator © Copyright 1998-2001 Pavel Haiduc, HP InfoTech S.R.L. http://infotech.ir.ro e-mail:dhptechn@ir.ro , hpinfotech@mail.com Project : Version : Date : 4/12/2001 Author : License #1 Company : Cornell University Ithaca NY USA Comments: Chip type : AT90S8515 Clock frequency : 4.000000 MHz Memory model : Small Internal SRAM size : 512 External SRAM size : 0 Data Stack size : 128 *********************************************/ #include <90s8515.h> #include #include #include #define ir_repeat 3 #define carrier_on 0x40 #define carrier_off 0xC0 #define maxkeys 30 //state machine variables #define reset 0 #define countkey 1 #define pressed 2 #define released 3 #define countrel 4 #define stillrel 5 /* Use an 1x16 alphanumeric LCD connected to PORTC as follows: [LCD] [AT90S8515 DIP40] 1 GND- 20 GND 2 +5V- 40 VCC 3 VLC 10k trimpot wiper (trimpot ends go to +5 and gnd) 4 RS - 21 PC0 5 RD - 22 PC1 6 EN - 23 PC2 14 BUSY - PC3 11 D4 - 25 PC4 12 D5 - 26 PC5 13 D6 - 27 PC6 14 D7 - 28 PC7 */ #asm .equ __lcd_port=0x15 #endasm #include // LCD driver routines //define keypad button numbers #define stop 1 #define pause 2 #define play 3 #define source1 4 #define rew 5 #define ff 6 #define mute 7 #define source2 8 #define prev 9 #define next 10 #define disp 11 #define source3 12 #define rec 13 #define pwr 14 #define source4 15 #define one 16 #define two 17 #define three 18 #define volup 19 #define four 20 #define five 21 #define six 22 #define voldn 23 #define seven 24 #define eight 25 #define nine 26 #define shuffle 27 #define ten 28 #define repeat 29 #define cont 30 #define reload 256-78 //LCD display constants #define mute_display 1 #define pause_display 2 #define record_display 3 // Declare your global variables here //The keypad lookup table flash unsigned char keytbl [30] = {0xee, 0xde, 0xbe, 0x7e, 0xed, 0xdd, 0xbd, 0x7d, 0xeb, 0xdb, 0xbb, 0x7b, 0xd7, 0xb7, 0x77, 0xe6, 0xc6, 0xa6, 0x66, 0xe5, 0xc5, 0xa5, 0x65, 0xe3, 0xc3, 0xa3, 0x63, 0xc7, 0xa7, 0x67}; //the CD IR-command table flash int cdtbl [30] = {0x8B8, 0x8B9, 0x8B2, 0x0, 0x8B3, 0x8b4, 0x0, 0x0, 0x8B0, 0x8B1, 0x0, 0x0, 0x8BE, 0x895, 0x0, 0x880, 0x881, 0x882, 0x0, 0x883, 0x884, 0x885, 0x0, 0x886, 0x887, 0x888, 0x8B5, 0x8A0, 0x8AC, 0x89D}; //the MiniDisc command table flash int mdtbl [30] = {0x7A8, 0x7A9, 0x7AA, 0x0, 0x7AB, 0x7AC, 0x0, 0x0, 0x7A0, 0x7A1, 0x798, 0x0, 0x7AD, 0x795, 0x0, 0x780, 0x781, 0x782, 0x0, 0x783, 0x784, 0x785, 0x0, 0x786, 0x787, 0x788, 0x79E, 0x789, 0x7A6, 0x79D}; //the winamp command table flash char winamptbl [30] = {'v', 'c', 'x', '-', 'g', 'h', 'm', '-', 'z', 'b', 't', '-', '-', 'f', '-', '-', '-', '-', 'p', '-', '-', '-', 'l', '-', '-', '-', 's', '-', 'r', '-'}; //Setup the UART /* quartz crystal frequency [Hz] */ #define xtal 4000000L /* Baud rate */ #define baud 9600 //The Winamp title buffer char lcd_buffer[80]; //buffer array index unsigned char index=0; //the keypad port read unsigned char key; //the debounce state machine run flag unsigned char run=0; //the length of the title received from Winamp unsigned char string_len=0; //control variable to run the winamp lcd titler unsigned char title_lcd=0; //the 500msec counter for LCD scrolling unsigned char title_count=0; //the current IR instruction to be transmitted int ir_data; //the current uart instruction to be transmitted char uart_data; //IR code transmission mask unsigned int mask; //decoded keypad button number unsigned char butnum; //the code of the current active audio source unsigned char active=source1; //the debounce state machine state variable unsigned char keycheck_state=reset; //keypad state machine variables unsigned char oldbutnum, count; //the LCD scrolling index unsigned char display_index=0; //flag for reserving the LCD for displaying cuurent commands unsigned char Lcd_override=0; unsigned char old_Lcd_override=0; //timer 0 overflow index interrupt [TIM0_OVF] timer0_ovf(void){ //reload the register TCNT0=reload; //run the debounce state machine run=1; //run the LCD scroller every 500msec if (title_count==100) { title_lcd=1; title_count=0; } else title_count++; } //the UART receive interrupt interrupt [UART_RXC] void uart_rec(void){ unsigned char i; //limit the size of the input string if (index<64){ lcd_buffer[index]=UDR; //get a char index++; display_index=0; string_len=0; //if the received character ends transmission if (lcd_buffer[index-1]=='\r'){ string_len=index; index=0; //print the title to the LCD title_lcd=1; //padding title with spaces for easy viewing for(i=string_len-1;i<(string_len+16);i++) { lcd_buffer[i]=' '; } } } } //keypad check routine void keycheck (void) { //read in the keys, 1 nibble at a time key=0; DDRA=0x0f; PORTA = 0xf0; delay_us(5); key = PINA; DDRA=0xf0; PORTA = 0x0f; delay_us(5); key = key|PINA; //check the keypad table, if found, it is valid if (key!=0){ for(butnum=0;butnum=string_len-1) { display_index=0; } } } } }