uint8_t LCD_DisplayMenu() { int8_t keycount=0; LCD_Clear(); LCD_GoToLine(1); LCD_DisplayString(" Settings "); do { if (util_IsBitCleared(Button, cancel)) { return (-1); } if(util_IsBitCleared(Button, up)) { keycount++; _delay_ms(100); } if(util_IsBitCleared(Button, down)) { keycount--; _delay_ms(100); } if((keycount>=menusize)||(keycount <= -menusize)) { keycount=0; } if(keycount<0) { //make menu index circular. i.e decrement from first //option shows the last option on the menu keycount += menusize; } LCD_GoToLine(2); LCD_DisplayString(" "); //clear second line //set cursor at the center of of line 2 depending on string size. LCD_SetCursor(2,(14-strlen(settings[keycount]))/2); LCD_Printf("<%s>", settings[keycount]); _delay_ms(100); //make menu visible or else will overwrite at fast speed }while(util_IsBitSet(Button,select)); do { if (util_IsBitCleared(Button, cancel)) { return (-1); ; } }while(util_IsBitSet(Button, select)); return (keycount); }
int main() { int adcValue; int temp; ADC_Init(); /* Initialize the ADC module */ /*Connect RS->PB0, RW->PB1, EN->PB2 and data bus PORTB.4 to PORTB.7*/ LCD_SetUp(PB_0,PB_1,PB_2,P_NC,P_NC,P_NC,P_NC,PB_4,PB_5,PB_6,PB_7); LCD_Init(2,16); while(1) { adcValue = ADC_GetAdcValue(0); // Read the ADC value of channel zero(PA0) where the temperature sensor(LM35) is connected /* Convert the raw ADC value to equivalent temperature with 5v as ADC reference Step size of AdC= (5v/1023)=4.887mv = 5mv. for every degree celcius the Lm35 provides 10mv voltage change. 1 step of ADC=5mv=0.5'c, hence the Raw ADC value can be divided by 2 to get equivalent temp*/ temp = adcValue/2.0; // Divide by 2 to get the temp value. LCD_GoToLine(0); LCD_Printf("ADC0 Value:%4d \nTemp:%dC\n\r",adcValue,temp); // Display adc value and temp LCD } return (0); }
/* start the main program */ void main() { unsigned char sec,min,hour,day,month,year; /* Initialize the lcd before displaying any thing on the lcd */ LCD_Init(8,2,16); /* Initialize the RTC(ds1307) before reading or writing time/date */ RTC_Init(); /*##### Set the time and Date only once. Once the Time and Date is set, comment these lines and reflash the code. Else the time will be set every time the controller is reset*/ RTC_SetTime(0x10,0x40,0x00); // 10:40:20 am RTC_SetDate(0x01,0x01,0x15); // 1st Jan 2015 /* Display the Time and Date continuously */ while(1) { LCD_GoToLine(1); /* Read the Time from RTC(ds1307) */ RTC_GetTime(&hour,&min,&sec); /* Read the Date from RTC(ds1307) */ RTC_GetDate(&day,&month,&year); LCD_Printf("\n\rtime:%2x:%2x:%2x \nDate:%2x/%2x/%2x",(uint16_t)hour,(uint16_t)min,(uint16_t)sec,(uint16_t)day,(uint16_t)month,(uint16_t)year); } }
void LCD_DisplayTime(unsigned char hr,unsigned char min, unsigned char sec) { uint8_t d_hour, d_min, d_sec; uint8_t digit0=0, digit1=0, digit2=0; d_hour = bcd2dec(hr); d_min = bcd2dec(min); d_sec = bcd2dec(sec); if ( Time_Format == 1 ) // 12 hour format { LCD_SetCursor(1,14); if (d_hour >12) { d_hour -= 12; LCD_Printf("PM"); } else { if ( d_hour == 0) // time is 12 AM { d_hour = 12; } LCD_Printf("AM"); } } if ( Display_Style == 1) // both date and time are displayed in this style { LCD_GoToLine(1); LCD_Printf(" %2d:%2d:%2d",d_hour,d_min,d_sec); } else // only date is displayed, so display big numbers { digit1 = d_hour/10; digit0= d_hour%10; LCD_DisplayBigNum(digit1,0); //display hour LCD_DisplayBigNum(digit0,3); // set colon LCD_SetCursor(1,6); lcd_DataWrite(0xA5); LCD_SetCursor(2,6); lcd_DataWrite(0xA5); //display min digit1 = d_min/10; digit0= d_min%10; LCD_DisplayBigNum(digit1,7); LCD_DisplayBigNum(digit0,10); //display sec LCD_SetCursor(2,14); LCD_Printf("%2x",sec); } }
/* start the main program */ void main() { unsigned char eeprom_address=0x00, write_char = 'X', read_char; /* Initialize the lcd before displaying any thing on the lcd */ LCD_Init(4,2,16); while(1) { LCD_GoToLine(1); // Move the cursor to first line LCD_DisplayString("Eeprom Write: "); //Display the message on first line LCD_DisplayChar(write_char); //Display the char to be written EEPROM_WriteByte(eeprom_address,write_char); // Write the data at memoryLocation 0x00 LCD_GoToLine(2); // Move the cursor to Second line LCD_DisplayString("Eeprom Read: "); //Display the message on first line read_char = EEPROM_ReadByte(eeprom_address); // Read the data from memoryLocation 0x00 LCD_DisplayChar(read_char); //Display the read data } }
void LCD_DisplayDate(uint8_t day, uint8_t month, uint8_t year) { unsigned char digit0=0, digit1=0, digit2=0; if ( Display_Style == 1) { LCD_GoToLine(2); digit0 = bcd2dec(day); digit1 = bcd2dec(month); digit2 = bcd2dec(year); LCD_Printf(" %2d/%2d/%2d",digit0,digit1,digit2); } }
/* start the main program */ void main() { uint16_t adc_result0,adc_result1,adc_result2,adc_result3; LCD_Init(4,2,16); /* Initialize 2x16lcd in 8-bit mode */ ADC_Init(); /* Initialize the adc module*/ while(1) { /* Get the adc value of first four channels */ adc_result0= ADC_GetAdcValue(0); adc_result1= ADC_GetAdcValue(1); adc_result2= ADC_GetAdcValue(2); adc_result3= ADC_GetAdcValue(3); LCD_GoToLine(1); LCD_Printf("C0:%d C1:%d \nC2:%d C3:%d ",adc_result0,adc_result1,adc_result2,adc_result3); } }
int main() { int adcValue; float volt; SystemInit(); ADC_Init(); /* Initialize the ADC module, Note: Max ADC Input voltage 3.3v */ /*Connect RS->P1_16, RW->P1_17, EN->P1_18 and data bus(D4:D7 - P1_20:P1_23)*/ LCD_SetUp(P1_16,P1_17,P1_18,P_NC,P_NC,P_NC,P_NC,P1_20,P1_21,P1_22,P1_23); LCD_Init(2,16); while(1) { adcValue = ADC_GetAdcValue(AD0_1); // Read the ADC value of channel AD0.1, Max ADC voltage 3.3v volt = (adcValue*3.3)/1023; // ADC_REF Voltage=3.3v and ADC resolution 10bit LCD_GoToLine(0); LCD_Printf("ADC0 Value:%4d\nVolt:%f",adcValue,volt); // Display Raw adc value and Equivalent temp on LCD } }
void checkAlarm() { uint8_t b_hour, b_min, b_sec; RTC_GetTime(&b_hour,&b_min,&b_sec); if ( (alarm_hour == b_hour) & ( alarm_min == b_min) & ( alarm_sec == b_sec) ) { LCD_Clear(); do { LCD_GoToLine(1); LCD_Printf("Press Cancel to Stop Alarm"); }while(util_IsBitSet(Button, cancel)); util_BitClear(buzzer_port,buzzer_pin); LCD_Clear(); } }
int main() { int count = 0; /*Connect RS->P0.0, RW->P0.1, EN->P0.2 and data bus to P0.4 to P0.7*/ LCD_SetUp(P0_0,P0_1,P0_2,P_NC,P_NC,P_NC,P_NC,P0_4,P0_5,P0_6,P0_7); LCD_Init(2,16); LCD_DisplayString("Decimal"); while(1) { LCD_GoToLine(1); LCD_Printf("Count=%4d",count); DELAY_ms(500); count++; } return (0); }
int main (void) { SystemInit(); /* RS RW EN D0 D1 D2 D3 D4 D5 D6 D7 P_NC(Not connected)*/ LCD_SetUp(P2_0,P2_1,P2_2,P_NC,P_NC,P_NC,P_NC,P1_24,P1_25,P1_26,P1_27); LCD_Init(2,16); /* EINT0 is configured as FallingEdge interrupt and myExtIntrIsr_0 will be called by EINT0_IRQHandler */ EINT_AttachInterrupt(EINT0,myExtIntrIsr_0,FALLING); /* EINT1 is configured as Active Low interrupt and myExtIntrIsr_1 will be called by EINT1_IRQHandler */ EINT_AttachInterrupt(EINT1,myExtIntrIsr_1,LOW); while(1) { LCD_GoToLine(0); LCD_Printf("EINT0=%8u EINT1:%8u",cnt1,cnt2); /* Display the occurrence of EINT0 and EINT1 */ } }
int main() { int count = 0; SystemInit(); /*Connect RS->PD0, RW->PD1, EN->PD2 and data bus to PORTB*/ LCD_SetUp(P2_0,P2_1,P2_2,P1_20,P1_21,P1_22,P1_23,P1_24,P1_25,P1_26,P1_27); LCD_Init(2,16); LCD_DisplayString("Decimal"); while(1) { LCD_GoToLine(1); LCD_Printf("Count=%4d",count); DELAY_ms(500); count++; } }
int main() { uint16_t pot_value,ldr_value, temp_raw, temp_final; float voltage; SystemInit(); //Clock and PLL configuration /* Setup/Map the controller pins for LCD operation RS RW EN D0 D1 D2 D3 D4 D5 D6 D7*/ LCD_SetUp(P2_0,P2_1,P2_2,P1_20,P1_21,P1_22,P1_23,P1_24,P1_25,P1_26,P1_27); LCD_Init(2,16); /* Specify the LCD type(2x16) for initialization*/ ADC_Init(); /* Initialize the ADC */ while(1) { pot_value = ADC_GetAdcValue(0); /* Read pot value connect to AD0(P0_23) */ ldr_value = ADC_GetAdcValue(1); /* Read LDR value connect to AD1(P0_24) */ temp_raw = ADC_GetAdcValue(2); /* Read Temp value connect to AD2(P0_25) */ /* Converting the raw adc value to equivalent temperature with 3.3v as ADC reference using 12bit resolution. Step size of ADC= (3.3v/2^12)= 3.3/4096 = 0.0008056640625 = 0.0806mv For every degree celcius the Lm35 provides 10mv voltage change. 1 degree celcius = 10mv = 10mv/0.0806mv = 12.41 uinits Hence the Raw ADC value can be divided by 12.41 to get equivalent temp */ temp_final = temp_raw/12.41; /* Vin = (Adc_value * REF)/ 2^12 */ voltage = (pot_value * 3.3)/ 4096.0; LCD_GoToLine(0); LCD_Printf("P:%4d %f",pot_value,voltage); LCD_Printf("\nL:%4d T:%4d",ldr_value,temp_final); } }
void LCD_ScrollMessage(uint8_t v_lineNumber_u8, char *ptr_msgPointer_u8) { unsigned char i,j; if(v_lineNumber_u8 >= LCDConfig.v_MaxSupportedLines_U8) v_lineNumber_u8 = C_LcdLineZero; // Select first line if the v_lineNumber_u8 is out of range LCD_CmdWrite(CMD_DISPLAY_ON_CURSOR_OFF); //Disable the Cursor for(i=0;ptr_msgPointer_u8[i];i++) { /* Loop to display the complete string, each time 16 chars are displayed and pointer is incremented to point to next char */ LCD_GoToLine(v_lineNumber_u8); //Move the Cursor to first line for(j=0;(j<LCDConfig.v_MaxSupportedChars_U8) && (ptr_msgPointer_u8[i+j]);j++) { //Display first 16 Chars or till Null char is reached LCD_DisplayChar(ptr_msgPointer_u8[i+j]); } while( j<LCDConfig.v_MaxSupportedChars_U8) { /*If the chars to be scrolled are less than MaxLcdChars, then display remaining chars with blank spaces*/ LCD_DisplayChar(' '); j++; } DELAY_ms(C_ScrollDelayTime_U8); } LCD_CmdWrite(CMD_DISPLAY_ON_CURSOR_ON); // Finally enable the Cursor }
int main() { rtc_t rtc; /*Connect RS->PB0, RW->PB1, EN->PB2 and data bus to PORTB.4 to PORTB.7*/ LCD_SetUp(PB_0,PB_1,PB_2,P_NC,P_NC,P_NC,P_NC,PB_4,PB_5,PB_6,PB_7); LCD_Init(2,16); RTC_Init(); rtc.hour = 0x10; // 10:40:20 am rtc.min = 0x40; rtc.sec = 0x00; rtc.date = 0x01; //1st Jan 2016 rtc.month = 0x01; rtc.year = 0x16; rtc.weekDay = 5; // Friday: 5th day of week considering monday as first day. /*##### Set the time and Date only once. Once the Time and Date is set, comment these lines and reflash the code. Else the time will be set every time the controller is reset*/ RTC_SetDateTime(&rtc); // 10:40:20 am, 1st Jan 2016 /* Display the Time and Date continuously */ while(1) { RTC_GetDateTime(&rtc); LCD_GoToLine(0); LCD_Printf("time:%2x:%2x:%2x \nDate:%2x/%2x/%2x",(uint16_t)rtc.hour,(uint16_t)rtc.min,(uint16_t)rtc.sec,(uint16_t)rtc.date,(uint16_t)rtc.month,(uint16_t)rtc.year); } return (0); }
void setDate(uint8_t day, uint8_t month, uint8_t year) { uint8_t d_day, d_month, d_year; d_day = bcd2dec(day); d_month = bcd2dec(month); d_year= bcd2dec(year); LCD_Clear(); LCD_GoToLine(1); LCD_Printf(" DD MM YY"); LCD_GoToLine(2); LCD_Printf("<%2d> <%2d> <%2d>" , d_day, d_month, d_year); do { LCD_SetCursor(2,1); _delay_ms(100); if (util_IsBitCleared(Button, cancel)) { return (-1); ; } if(util_IsBitCleared(Button, up)) { d_day++; _delay_ms(200); } if(util_IsBitCleared(Button, down)) { d_day--; _delay_ms(200); } if(d_day>31) { d_day=0; } LCD_Printf("%2d",d_day); } while (util_IsBitSet(Button, select)); do { if (util_IsBitCleared(Button, cancel)) { return (-1); ; } }while(util_IsBitSet(Button, select)); //update month do { LCD_SetCursor(2,7); _delay_ms(100); if (util_IsBitCleared(Button, cancel)) { return (-1); ; } if(util_IsBitCleared(Button, up)) { d_month++; _delay_ms(200); } if(util_IsBitCleared(Button, down)) { d_month--; _delay_ms(200); } if(d_month>12) { d_month=0; } LCD_Printf("%2d",d_month); } while (util_IsBitSet(Button, select)); do { if (util_IsBitCleared(Button, cancel)) { return (-1); ; } }while(util_IsBitSet(Button, select)); //set year do { LCD_SetCursor(2,12); _delay_ms(100); if (util_IsBitCleared(Button, cancel)) { return (-1); ; } if(util_IsBitCleared(Button, up)) { d_year++; _delay_ms(200); } if(util_IsBitCleared(Button, down)) { d_year--; _delay_ms(200); } if(d_year>=99) { d_year=0; } LCD_Printf("%2d",d_year); } while (util_IsBitSet(Button, select)); do { if (util_IsBitCleared(Button, cancel)) { return (-1); ; } }while(util_IsBitSet(Button, select)); day = dec2bcd(d_day); month = dec2bcd(d_month); year = dec2bcd(d_year); RTC_SetDate(day, month, year); LCD_Clear(); LCD_DisplayString("Date Updated"); _delay_ms(2000); }
void setAlarm() { uint8_t d_hour, d_min, d_sec; d_hour = bcd2dec(alarm_hour); d_min = bcd2dec(alarm_min); d_sec = bcd2dec(alarm_sec); LCD_Clear(); LCD_GoToLine(1); LCD_Printf("Hour Min Sec"); LCD_GoToLine(2); LCD_Printf("<%2d> <%2d> <%2d>" , d_hour, d_min, d_sec); do { LCD_SetCursor(2,1); _delay_ms(100); if (util_IsBitCleared(Button, cancel)) { return (-1); ; } if(util_IsBitCleared(Button, up)) { d_hour++; _delay_ms(200); } if(util_IsBitCleared(Button, down)) { d_hour--; _delay_ms(200); } if(d_hour>=24) { d_hour=0; } LCD_Printf("%2d",d_hour); } while (util_IsBitSet(Button, select)); do { if (util_IsBitCleared(Button, cancel)) { return (-1); ; } }while(util_IsBitSet(Button, select)); //update min do { LCD_SetCursor(2,7); _delay_ms(100); if (util_IsBitCleared(Button, cancel)) { return (-1); ; } if(util_IsBitCleared(Button, up)) { d_min++; _delay_ms(200); } if(util_IsBitCleared(Button, down)) { d_min--; _delay_ms(200); } if(d_min>=60) { d_min=0; } LCD_Printf("%2d",d_min); } while (util_IsBitSet(Button, select)); do { if (util_IsBitCleared(Button, cancel)) { return (-1); ; } }while(util_IsBitSet(Button, select)); do { LCD_SetCursor(2,12); _delay_ms(100); if (util_IsBitCleared(Button, cancel)) { return (-1); ; } if(util_IsBitCleared(Button, up)) { d_sec++; _delay_ms(200); } if(util_IsBitCleared(Button, down)) { d_sec--; _delay_ms(200); } if(d_sec>=60) { d_sec=0; } LCD_Printf("%2d",d_sec); } while (util_IsBitSet(Button, select)); do { if (util_IsBitCleared(Button, cancel)) { return (-1); ; } }while(util_IsBitSet(Button, select)); alarm_hour = dec2bcd(d_hour); alarm_min = dec2bcd(d_min); alarm_sec = dec2bcd(d_sec); LCD_Clear(); LCD_DisplayString("Alarm Set"); _delay_ms(2000); }
/*************************************************************************************************** void LCD_Clear() **************************************************************************************************** * I/P Arguments: none. * Return value : none * description :This function clears the LCD and moves the cursor to beginning of first line ****************************************************************************************************/ void LCD_Clear(void) { LCD_CmdWrite(CMD_LCD_CLEAR); // Clear the LCD and go to First line First Position LCD_GoToLine(C_LcdLineZero); }
void setTimeFormat() { LCD_Clear(); LCD_GoToLine(1); LCD_Printf(" Time Format "); do { LCD_GoToLine(2); _delay_ms(100); if (util_IsBitCleared(Button, cancel)) { return (-1); ; } if(util_IsBitCleared(Button, up)) { Time_Format++; _delay_ms(200); } if(util_IsBitCleared(Button, down)) { Time_Format--; _delay_ms(200); } if((Time_Format >= 2)||(Time_Format <= -2)) { Time_Format = 0; } if(Time_Format < 0) { //make menu index circular. i.e decrement from first //option shows the last option on the menu Time_Format += 2; } if( Time_Format == 1 ) { LCD_Printf(" <12 Hours> "); } else { LCD_Printf(" <24 Hours> "); } } while (util_IsBitSet(Button, select)); do { if (util_IsBitCleared(Button, cancel)) { return (-1); ; } }while(util_IsBitSet(Button, select)); LCD_GoToLine(1); LCD_Printf(" Time Format \n Updated "); _delay_ms(2000); }
void setDisplayStyle() { LCD_Clear(); LCD_GoToLine(1); LCD_Printf(" Display-Style "); do { LCD_GoToLine(2); _delay_ms(100); if (util_IsBitCleared(Button, cancel)) { return (-1); ; } if(util_IsBitCleared(Button, up)) { Display_Style++; _delay_ms(200); } if(util_IsBitCleared(Button, down)) { Display_Style--; _delay_ms(200); } if((Display_Style >= 2)||(Display_Style <= -2)) { Display_Style = 0; } if(Display_Style < 0) { //make menu index circular. i.e decrement from first //option shows the last option on the menu Display_Style += 2; } if(Display_Style == 1) { LCD_Printf(" <Time + Date> "); } else { LCD_Printf(" <Only Time> "); } } while (util_IsBitSet(Button, select)); do { if (util_IsBitCleared(Button, cancel)) { return (-1); ; } }while(util_IsBitSet(Button, select)); LCD_GoToLine(1); LCD_Printf(" Display-Style \n Updated "); _delay_ms(2000); }