void FloatToLCD(float data, unsigned char countDs, unsigned char pos) { unsigned int tempSt = 0; unsigned int tempDec = 0; unsigned char buf[5]; tempSt = (unsigned int)data; tempDec = (unsigned int)((data - tempSt)*10); pos += 4; if (tempSt > 9) pos--; if (tempSt > 99) pos--; if (tempSt > 999) pos--; pos -= 2; SetDDRamAddr(pos); itoa(tempSt, buf); putsXLCD(buf); pos++; if (tempSt > 9) pos++; if (tempSt > 99) pos ++; if (tempSt > 999) pos ++; SetDDRamAddr(pos); WriteDataXLCD(0x2E); pos++; SetDDRamAddr(pos); itoa(tempDec, buf); putsXLCD(buf); }
void printLCD(char *line1, char *line2) { openLCD(); while (BusyXLCD()); SetDDRamAddr(0x80); while (BusyXLCD()); putsXLCD(line1); while (BusyXLCD()); SetDDRamAddr(0xc0); while (BusyXLCD()); putsXLCD(line2); }
void LCD_WriteFirstLine(char OutFirstString[]){ while (BusyXLCD()); SetDDRamAddr(0x00); while (BusyXLCD()); putsXLCD(OutFirstString); while (BusyXLCD()); WriteCmdXLCD(CURSOR_OFF&BLINK_OFF); //cursor uit, knipperen uit }
void LCD_Write(void){ while (BusyXLCD()); SetDDRamAddr(0x00); while (BusyXLCD()); putsXLCD(LCDREGEL4); Delay10KTCYx(250); // 500 mSec Delay10KTCYx(250); // 500 mSec while (BusyXLCD()); SetDDRamAddr(0x40); while (BusyXLCD()); putsXLCD(LCDREGEL5); while (BusyXLCD()); WriteCmdXLCD(CURSOR_OFF&BLINK_OFF); //cursor uit, knipperen uit }
void rotina_sai_modificacao(void) { if(sai_modificacao == 1){ mudei_horas = 0; mudei_ahoras = 0; mudei_alum = 0; mudei_atemp = 0; d_a_alarmes = 0; alarme_temp_prev = alarme_temp; alarme_lum_prev = alarme_lum; alarme_hours_prev = alarme_hours; alarme_minutes_prev = alarme_minutes; alarme_seconds_prev = alarme_seconds; alarmes_prev[0] = alarmes[0]; change_AH = 1; SetDDRamAddr(0x46); while( BusyXLCD() ); putrsXLCD((const rom far char*)" "); SetDDRamAddr(0x09); while( BusyXLCD() ); sprintf((char*)spaces, (const rom far char*)" "); putsXLCD(spaces); SetDDRamAddr(0x4D); while( BusyXLCD() ); sprintf((char*)luminosidade, (const rom far char*)"L %d", n_lum); putsXLCD(luminosidade); SetDDRamAddr(0x40); while( BusyXLCD() ); sprintf((char*)temperatura_s, (const rom far char*)"%d C", (int)temperatura); putsXLCD(temperatura_s); sai_modificacao = 0; } }
void IntToLCD(unsigned int data, unsigned char pos) { unsigned char buf[5]; itoa(data, buf); pos += 4; if (data > 9) pos--; if (data > 99) pos--; if (data > 999) pos--; SetDDRamAddr(pos); putsXLCD(buf); }
void main(void) { ADCON1 = 0b11111111; // Configure all pins digital // For me it not want work without it //******** Configure LCD for four line communication and 5X7 line display ********************************* OpenXLCD(FOUR_BIT & LINES_5X7); while( BusyXLCD() ); //wait untill LCD controller is busy WriteCmdXLCD(CURSOR_OFF); while( BusyXLCD() ); WriteCmdXLCD(BLINK_OFF); while( BusyXLCD() ); //************************************************************************************************************* while(1){ //*********** Set the starting address in the LCD RAM for display. This determines the location of display ******** SetDDRamAddr(0x80); while( BusyXLCD() ); //wait untill LCD controller is busy putsXLCD(LCD_text1); //Display string of text while( BusyXLCD() ); //wait untill LCD controller is busy //********** Set the address in second line for display **************************************************** SetDDRamAddr(0xC0); while( BusyXLCD() ); //wait untill LCD controller is busy putsXLCD(LCD_text2); //Display string of text while( BusyXLCD() ); //wait untill LCD controller is busy WriteCmdXLCD(SHIFT_DISP_LEFT); while( BusyXLCD() ); } }
void clearBottomLCD(void) { unsigned char data[] = " "; SetDDRamAddr(0x28); putsXLCD(data); }
void clearTopLCD(void) { unsigned char data[] = " "; SetDDRamAddr(0x00); putsXLCD(data); }
void rotina_modo_modificacao(void) { if(modo_modificacao == 1){ // estamos em modo modificacao if(cursor_pos >= 4){ SetDDRamAddr(0x00); // First line, first column while( BusyXLCD() ); sprintf((char*)time_s, (const rom far char*)"%d%d:%d%d:%d%d", alarme_hd, alarme_hu, alarme_md, alarme_mu, alarme_sd, alarme_su); putsXLCD(time_s); } SetDDRamAddr(0x4D); while( BusyXLCD() ); sprintf((char*)luminosidade, (const rom far char*)"L %d", alarme_lum); putsXLCD(luminosidade); SetDDRamAddr(0x40); while( BusyXLCD() ); sprintf((char*)temperatura_s, (const rom far char*)"%d%d C", alarme_temp/10, alarme_temp%10); putsXLCD(temperatura_s); SetDDRamAddr(0x0F); while( BusyXLCD() ); putrsXLCD((const rom far char*)"P"); // letra P que so aparece quando em modo modificacaoo SetDDRamAddr(0x09); while( BusyXLCD() ); putrsXLCD((const rom far char*)"ATL"); // letras ATL que aparecem quando em modo modificaoo para se definir os alarmes SetDDRamAddr(0x0D); while( BusyXLCD() ); putsXLCD(alarmes); // letra a ou A para desactivar/activar alarmes if(cursor_pos == 1){ // acertar horas SetDDRamAddr(0x00); while(PORTAbits.RA4 && cursor_pos == 1); if(cursor_pos == 1){ hours++; mudei_horas=1; Delay1KTCYx(200); if (hours == 24){ hours = 0; } hd = hours/10; hu = hours%10; while( BusyXLCD() ); sprintf((char*)change_hours, (const rom far char*)"%d%d", hd, hu); putsXLCD(change_hours); update_EEPROM_interna_relogio_hours(); } } else if(cursor_pos == 2){ // acertar minutos SetDDRamAddr(0x03); while(PORTAbits.RA4 && cursor_pos == 2); if(cursor_pos == 2){ minutes++; mudei_horas=1; Delay1KTCYx(200); if (minutes == 60){ minutes = 0; } md = minutes/10; mu = minutes%10; while( BusyXLCD() ); sprintf((char*)change_minutes, (const rom far char*)"%d%d", md, mu); putsXLCD(change_minutes); update_EEPROM_interna_relogio_minutes(); } } else if(cursor_pos == 3){ // acertar segundos SetDDRamAddr(0x06); while(PORTAbits.RA4 && cursor_pos == 3); if(cursor_pos == 4 && mudei_horas == 1){ mudei_horas == 0; update_EEPROM_external(2); } if(cursor_pos == 3){ seconds++; mudei_horas = 1; Delay1KTCYx(200); // usado para resolver debounce - delay de 50ms if (seconds == 60){ seconds = 0; } sd = seconds/10; su = seconds%10; while( BusyXLCD() ); sprintf((char*)change_seconds, (const rom far char*)"%d%d", sd, su); putsXLCD(change_seconds); } } else if(cursor_pos == 4){ // acertar alarme do relogio if(change_A == 0){ SetDDRamAddr(0x09); } else{ if(change_AH == 1){ SetDDRamAddr(0x00); // colocar o cursor no sitio das dezenas das horas } else if(change_AM == 1){ SetDDRamAddr(0x03); // colocar o cursor no sitio das dezenas dos minutos } else if(change_AS == 1){ SetDDRamAddr(0x06); // colocar o cursor no sitio das dezenas dos segundos } } if(change_A == 0){ while(PORTAbits.RA4 && cursor_pos == 4); // carregar em S2 para indicar que se quer definir alarme } if(cursor_pos == 4){ if(change_AH == 1){ SetDDRamAddr(0x00); // colocar o cursor no sitio das dezenas das horas } Delay1KTCYx(200); change_A = 1; while(PORTAbits.RA4 && change_A == 1); // carregar em S2 uma vez para incrementar as horas if(mudei_ahoras == 1 && (alarme_hours_prev != alarme_hours || alarme_minutes_prev != alarme_minutes || alarme_seconds_prev != alarme_seconds )){ mudei_ahoras = 0; update_EEPROM_interna_relogio_alarme(); update_EEPROM_external(3); } if(change_A == 1){ if(change_AH == 1){ SetDDRamAddr(0x00); alarme_hours++; Delay1KTCYx(200); if (alarme_hours == 24){ alarme_hours = 0; } alarme_hd = alarme_hours/10; alarme_hu = alarme_hours%10; while( BusyXLCD() ); sprintf((char*)change_hours_alarme, (const rom far char*)"%d%d", alarme_hd, alarme_hu); putsXLCD(change_hours_alarme); } else if(change_AM == 1){ SetDDRamAddr(0x03); alarme_minutes++; Delay1KTCYx(200); if (alarme_minutes == 60){ alarme_minutes = 0; } alarme_md = alarme_minutes/10; alarme_mu = alarme_minutes%10; while( BusyXLCD() ); sprintf((char*)change_minutes_alarme, (const rom far char*)"%d%d", alarme_md, alarme_mu); putsXLCD(change_minutes_alarme); } else if(change_AS == 1){ SetDDRamAddr(0x06); alarme_seconds++; Delay1KTCYx(200); if (alarme_seconds == 60){ alarme_seconds = 0; } alarme_sd = alarme_seconds/10; alarme_su = alarme_seconds%10; while( BusyXLCD() ); sprintf((char*)change_seconds_alarme, (const rom far char*)"%d%d", alarme_sd, alarme_su); putsXLCD(change_seconds_alarme); } } } } else if(cursor_pos == 5){ // acertar alarme da temperatura if(change_T == 0){ SetDDRamAddr(0x0A); } else{ SetDDRamAddr(0x40); } if(change_T == 0){ while(PORTAbits.RA4 && cursor_pos == 5); // carregar em S2 para indicar que se quer definir alarme } if(cursor_pos == 5){ SetDDRamAddr(0x40); // levar o cursor ate ao sitio onde aparece o nivel da temperatura Delay1KTCYx(200); change_T = 1; while(PORTAbits.RA4 && change_T == 1); if(mudei_atemp == 1 && alarme_temp_prev != alarme_temp){ mudei_atemp = 0; update_EEPROM_interna_temp_alarme(); update_EEPROM_external(4); } if(change_T == 1){ alarme_temp++; if (alarme_temp == 40){ alarme_temp = 10; } Delay1KTCYx(200); Td = alarme_temp/10; Tu = alarme_temp%10; while( BusyXLCD() ); sprintf((char*)nova_T, (const rom far char*)"%d%d", Td, Tu); putsXLCD(nova_T); } } } else if(cursor_pos == 6){ // acertar alarme da luminosidade if(change_L == 0){ SetDDRamAddr(0x0B); } else{ SetDDRamAddr(0x4F); } if(change_L == 0){ while(PORTAbits.RA4 && cursor_pos == 6); // carregar em S2 para indicar que se quer definir alarme } if(cursor_pos == 6){ SetDDRamAddr(0x4F); // levar o cursor ate ao sitio onde aparece o nivel da luminosidade Delay1KTCYx(200); change_L = 1; while(PORTAbits.RA4 && change_L == 1); // carregar novamente em S2 para incrementar "n" e definir o valor de luminosidade pretendido if(mudei_alum == 1 && alarme_lum_prev != alarme_lum){ mudei_alum = 0; update_EEPROM_interna_lum_alarme(); update_EEPROM_external(5); } if(change_L == 1){ if(alarme_lum < 5){ alarme_lum++; } else{ alarme_lum = 0; } Delay1KTCYx(200); while( BusyXLCD() ); sprintf((char*)nova_L, (const rom far char*)"%d", alarme_lum); putsXLCD(nova_L); } } } else if(cursor_pos == 7){ // activar/desactivar alarmes SetDDRamAddr(0x0D); while(PORTAbits.RA4 && cursor_pos == 7 && alarme_OFF == 1); if(d_a_alarmes == 1 && alarmes_prev[0] != alarmes[0]){ d_a_alarmes = 0; update_EEPROM_external(6); } if(cursor_pos == 7 && alarme_OFF == 1){ Delay1KTCYx(200); if(alarmes[0] == 'a'){ alarmes[0] = 'A'; } else{ alarmes[0] = 'a'; } while( BusyXLCD() ); putsXLCD(alarmes); } } else{ //activar modo poupanca de energia SetDDRamAddr(0x0F); if (modo_sleep == 0) while(PORTAbits.RA4 && cursor_pos == 8); if(cursor_pos == 8){ modo_sleep = 1; Delay1KTCYx(200); while( BusyXLCD() ); WriteCmdXLCD(DOFF); Sleep(); } } } else{ // nao esta no modo modificao SetDDRamAddr(0x00); // First line, first column while( BusyXLCD() ); sprintf((char*)time_s, (const rom far char*)"%d%d:%d%d:%d%d", hd, hu, md, mu, sd, su); putsXLCD(time_s); } }
void main (void) { /* TIMER 1*/ OpenTimer1( TIMER_INT_ON & T1_16BIT_RW & T1_SOURCE_EXT & T1_PS_1_1 & T1_OSC1EN_ON & T1_SYNC_EXT_OFF );// tem que estar off para correr na placa, mas on para correr no proteus ADCON1 = 0x0E; // Port A: A0 - analog; A1-A7 - digital OpenADC (ADC_FOSC_RC & ADC_RIGHT_JUST & ADC_1ANA_0REF, ADC_CH0 & ADC_INT_OFF); /* BUTTON S3 */ OpenRB0INT ( PORTB_CHANGE_INT_ON & /* enable the RB0/INT0 interrupt */ PORTB_PULLUPS_ON & /* configure the RB0 pin for input */ FALLING_EDGE_INT); /* trigger interrupt upon S3 button depression */ OpenXLCD( FOUR_BIT & LINES_5X7 ); // 4-bit data interface; 2 x 16 characters OpenI2C(MASTER, SLEW_ON);// Initialize I2C module SSPADD = 9; //400kHz Baud clock(9) @16MHz //100kHz Baud clock(39) @16MHz InitializeBuzzer(); init_LVD(); EnableHighInterrupts(); alarmes[0] = 'a'; alarmes[1] = 0; alarmes_prev[0] = 'a'; alarmes_prev[1] = 0; checksumIsRight = verificar_checksum(); if(checksumIsRight == 1){ ler_EEPROM_interna_parametros(); ler_EEPROM_interna_relogio(); ler_EEPROM_interna_relogio_alarme(); // carregar da EEPROM interna o valor do alarme do relogio ler_EEPROM_interna_temp_alarme(); // carregar da EEPROM interna o valor do alarme da temperatura ler_EEPROM_interna_lum_alarme(); // carregar da EEPROM interna o valor do alarme da luminosidade } ler_EEPROM_interna_relogio_seconds(); update_EEPROM_interna_parametros(); update_EEPROM_interna_relogio_alarme(); update_EEPROM_interna_temp_alarme(); update_EEPROM_interna_lum_alarme(); update_EEPROM_interna_relogio_hours(); update_EEPROM_interna_relogio_minutes(); init_EEPROM_externa(); WriteTimer1( 0x8000 ); // load timer: 1 second /////////////////////////////////////////////////////////////////////////////// //*************************** Ciclo Principal *******************************// /////////////////////////////////////////////////////////////////////////////// while (1){ if(modo_sleep == 1 && cursor_pos == 8){ WriteCmdXLCD( DOFF ); // Turn display off } else{ while( BusyXLCD() ); WriteCmdXLCD( DOFF ); // Turn display off while( BusyXLCD() ); WriteCmdXLCD( CURSOR_OFF );// Enable display with no cursor while( BusyXLCD() ); } sd = seconds/10; su = seconds%10; md = minutes/10; mu = minutes%10; hd = hours/10; hu = hours%10; SetDDRamAddr(0x0D); putsXLCD(alarmes); rotina_verificacao_alarmes(); rotina_modo_modificacao(); rotina_sai_modificacao(); avisa_alarmes(); rotina_sensores_PMON(); if(CCP1CON == 0x00 && modo_modificacao == 0){ modo_sleep = 1; Sleep(); } } }
int main( void ) { int adcvalue; char buf[20]; Setup(); //LCD display OpenXLCD(FOUR_BIT&LINES_5X7); Delay(50000); while(BusyXLCD()); SetDDRamAddr(0); putsXLCD("EE4207 Lab"); while(BusyXLCD()); SetDDRamAddr(0x40); putsXLCD("Demo 1"); while(1) { adcvalue = ReadADC(7); if (adcvalue <200 && adcvalue >=0) { LED1 = 0; LED2 = 0; LED3 = 0; LED4 = 0; } if (adcvalue <400 && adcvalue >=200) { LED1 = 1; LED2 = 0; LED3 = 0; LED4 = 0; } if (adcvalue <600 && adcvalue >=400) { LED1 = 1; LED2 = 1; LED3 = 0; LED4 = 0; } if (adcvalue <800 && adcvalue >=600) { LED1 = 1; LED2 = 1; LED3 = 1; LED4 = 0; } if (adcvalue >800) { LED1 = 1; LED2 = 1; LED3 = 1; LED4 = 1; } sprintf(buf, "%d ", adcvalue); SetDDRamAddr(0x47); putsXLCD("ADC="); SetDDRamAddr(0x4B); putsXLCD(buf); } // end while(1) } // end main