void LCDinit(void) { //Initialize Pins for LCD screen TRISA = 0; //Make Register A all outputs for LCD data TRISEbits.RE0 = 0; //Make RE0 an output for LCD RS pin TRISEbits.RE1 = 0; //Make RE1 an output for LCD R/W pin TRISEbits.RE2 = 0; //Make RE2 an output for LCD E pin //Initialize LCD; Busy Flag cannot be checked yet! LATEbits.LATE0 = 0; //Turn RS pin low for LCD initialization LATEbits.LATE1 = 0; //Turn R/W pin low for LCD initialization LATEbits.LATE2 = 1; //Turn E pin high to wait for first instruction __delay_ms(50); LCDcmd(0b00110000); //Function Set for 8-bit interface __delay_ms(60); LCDcmd(0b00110000); //Function Set for 8-bit interface __delay_ms(60); LCDcmd(0b00110000); //Function Set for 8-bit interface __delay_ms(60); LCDcmd(0b00111000); //8-bits, 2 lines, 5x8 font __delay_ms(60); LCDcmd(0b00001000); //Display Off (for initialization) __delay_ms(60); LCDcmd(0b00000001); //Display Clear __delay_ms(60); LCDcmd(0b00000110); //Entry Set Mode: increment AC, no shift __delay_ms(60); //Busy flag can now be checked //Now turn on display, cursor, and blink LCDcmd(0b00001111); //Display ON, Cursor ON, Blink ON LCDcheckBF(); //Check busy flag before doing anything else }
void welcome() { printString(" Cool Kids "); LCDcmd(0xC0,0); printString("ECT122 Theremin"); delaym(2000); }
void LCDgotoLineTwo(void) { LATEbits.LATE0 = 0; //Turn RS pin low for Instruction Register LATEbits.LATE1 = 0; //Turn R/W pin low for write LCDcmd(0b11000000); //Sets DDRAM address to 40h (begin line 2) LCDcheckBF(); //Check the busy flag before doing anything else }
void LCDclear(void) { LATEbits.LATE0 = 0; //Turn RS pin low for Instruction Register LATEbits.LATE1 = 0; //Turn R/W pin low for write LCDcmd(0b00000001); //Clears the LCD display LCDcheckBF(); //Check the busy flag before doing anything else }
void LCDwrite(char input) { LATEbits.LATE0 = 1; //Turn RS pin HIGH for Data Register LATEbits.LATE1 = 0; //Turn R/W pin low for write LCDcmd(input); //Write character to LCD LCDcheckBF(); //Check the busy flag before doing anything else }
/* initialize LCD with startup parameters *MAKE SURE INITLENGTH MATCHES* */ void LCDinit(void) { const char INITLENGTH = 6; char initseq[] = {0x33,0x32,0x28,0x06,0x0c,0x01}; char i; DDRK = 0xFF; PORTK = 0x00; for (i=0; i<INITLENGTH; i++) { LCDcmd(initseq[i], 0); delayu(5000); } }
/* display formats and prints data to LCD */ void display(unsigned char vol, unsigned char freq) { static char buffer[31]; if(PTH & 0x02) { LCDcmd(0x01,0); printString(" Debug Mode "); // implement conversion to freq (void)sprintf(buffer,"L1=%d L2=%d", freq, vol); // duty cycle -> volume % LCDcmd(0xC0,0); printString(buffer); } else { (void)sprintf(buffer,"Frequency..:%d", 25000/pitchSense); // implement conversion to freq LCDcmd(0x01,0); printString(buffer); (void)sprintf(buffer,"Volume.....:%d",100 * vol / 255); // duty cycle -> volume % LCDcmd(0xC0,0); printString(buffer); } vupdate(volSense); }
/* print string to LCD *NO PROVISIONS FOR WRAP* */ void printString(char *c) { while(*c){ LCDcmd(*(c++),1); } }
void main(void) { char ch; asm { clrf PORTA clrf PORTB bsf STATUS,RP0 movlw 0x0C movwf TRISA clrf TRISB bcf STATUS,RP0 } // Init both LCDs at the same time emask = E1 | E2; LCDinit(); // Say hi until the serial port says otherwise emask = E1; LCDstring("LCD interface ready"); emask = E2; LCDstring("Micah Dowty, July 2000"); emask = E1; // Wait for input while (1) { ch = getchar(); // Process escape chars if (ch == '\\') { ch = getchar(); switch (ch) { case '\\': LCDchar('\\'); break; case '1': // First display emask = E1; break; case '2': // Second display emask = E2; break; case '*': // All displays emask = E1 | E2; break; case 'c': // Next char is an LCD command ch = getchar(); LCDcmd(ch); break; case 's': // Clear screen LCDcmd(clear_lcd); break; case 'g': // Go to the beginning of CGRAM LCDcmd(set_cg_ram); break; case 'd': // Go to the beginning of DDRAM LCDcmd(set_dd_ram); break; case 'b': // Beep output_high_port_a(BEEPER); delay_ms(250); output_low_port_a(BEEPER); break; case 'f': // Flash output_high_port_a(LED); delay_ms(250); output_low_port_a(LED); break; case 'n': // Go to line 2 LCDcmd(set_dd_ram + 40); break; } } else { LCDchar(ch); } } }