unsigned int getkeyab(unsigned int dmin,unsigned int dmax,unsigned char display){ //bien x dung xac nhan dat timeout, nhap va0 so >=a <=b //unsigned char arrbuff[33];//so toi da 65536 la 5 chu + 1 null cua chuoi =6 unsigned char i,strmax,strmin,sobam; unsigned long digi=0,temp,toadotruyen=lcd_wait(); while(getbell()!=offbell); strmax=digi2text(lcd_buff,10,dmax)-1;//so chu so cua dmax, bi loi truyen tham so sai strmin=digi2text(lcd_buff,10,dmin)-1; if(display&minmax_){ sprintf(lcd_buff,"%u->%u",dmin,dmax); lcd_putsxy(lcd_buff,0,lines-1); lcd_goto(toadotruyen); } if(display&PAXX_)for(i=0;i<strmax+1;i++){lcd_putchar('X');} lcd_goto(toadotruyen); for(i=(strmax);i!=0xFF;i--){ //while(ir_in()); thulaichuso: delay_ms(100); while((temp=ir_getkeytimeout(offbell&(~diir_),0))>9);//tranh tran so ma thoi sobam=(unsigned char)temp+0x30; temp=digi+temp*xpowy(10,i); if(strmin<i){if(temp>dmax)goto thulaichuso;} else {if((temp<dmin)||(temp>dmax)) goto thulaichuso;} if(display&phimtm_)lcd_putchar(sobam); //xongthem1chuso: digi=temp; setbell(binhthuong); } setbell(bellsucsesful);//da nhap thanh cong while(getbell()!=offbell); return digi; }
void main( void ) { WDTCTL = WDTPW + WDTHOLD; BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ; __delay_cycles(100000); TA0CTL = TASSEL_2 + TACLR; TA0CCR0 = 50000-1; TA0CCTL0 = CCIE; lcd_init(); sicaklik_init(); lcd_goto(1,2); lcd_puts("mcu-turkey.com"); lcd_goto(2,2); lcd_puts("Sicaklik Olcme"); delay_ms(2000); lcd_temizle(); TA0CTL |= MC_1; //Timer Baþlatýlýyor... __bis_SR_register(LPM0_bits + GIE); }
void main(){ unsigned long buf,sp; unsigned char data,x,y,ch; #ifdef PARITYCHECK unsigned char parity; int tmp; #endif // char str[7]; prescaler_init(); init_mc(); spi_init(); lcd_init(); ch=x=y=0; lcd_goto(0); lcd_puts("initializing..."); init_lut(); lcd_clrscr(); lcd_goto(0); while(1){ state1: if(SPSR&(1<<SPIF)){ buf=SPDR; if(!(buf&1)){ buf=buf>>1; //throw out start bit. goto state2; } }
void main( void ) { WDTCTL = WDTPW + WDTHOLD; BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ; __delay_cycles(100000); TA0CTL = TASSEL_2 + TACLR; TA0CCR0 = 50000-1; TA0CCTL0= CCIE; lcd_init(); adc_init(); lcd_puts(" mcu-turkey.com"); lcd_goto(2,2); lcd_puts("DTC Uygulamasi"); delay_ms(2000); lcd_temizle(); lcd_puts("A0 = "); lcd_goto(2,1); lcd_puts("A1 = "); TA0CTL |= MC_1; __bis_SR_register(LPM0_bits + GIE); }
void deger_goster(unsigned int ham,unsigned int ham_s) { lcd_goto(1,1); lcd_puts("10 Bit = "); integer_yaz(ham,0); lcd_goto(2,1); lcd_puts("oC = "); integer_yaz(ham_s,1); }
//------------------------------- void lcd_readybar(void) { int8u_t i,j; for(i=0;i<NUMBER_OF_CELL_ELEMENTS;i++) { lcd_goto(CGRAM,(i*DRAW_CHAR_SIZE)); for(j=0;j<PROGRESS_BAR_HEIGHT;j++) lcd_putc(progress_bar[i]); } lcd_goto(1,0); }
void validPresetMenu(void) { lcd_goto(4, 2); lcd_print(" ^ "); lcd_goto(1, 1); lcd_command(curBank + 'A', 1); if (curPreset < 10) lcd_print(" "); lcd_printnbr(curPreset); lcd_print("-"); }
void screen_gotoxy(unsigned char x, unsigned char y) { #if LCD_ALIGNMENT == HORIZONTAL if (x >= LCD_0_WIDTH) lcd_goto(1, lcd1_line_addr[y] + (x - LCD_0_WIDTH)); else lcd_goto(0, lcd0_line_addr[y] + x); #endif screen_x = x; screen_y = y; }
// outputs test string void lcd_test(void) { lcd_goto(0); lcd_send(1,0b01100011); lcd_send(1,0b00110101); lcd_send(1,0b00001101); lcd_send(1,0b00000100); lcd_goto(64); lcd_send(1,0b01111010); lcd_send(1,0b11111010); lcd_send(1,0b01111010); }
/** *@brief The main function that initalizes the peripherals and displays the value returned by the adc in volts. *@retval None */ void main(void) { //Intialization function calls init(); //Intialize the PIC lcd_init(); //Initialize the lcd lcd_write(0x0C); //Turn off cursor lcd_goto(0x00); //Goto begining of the screen lcd_puts("Output Voltage"); //Display header adcInit(); //ADC setup //Values for the Voltage Meter int i; /**<Width of the Average*/ int low = 0; /**<Low end of the ADC value */ int high = 0; /**<High end of the ADC value*/ float Vin = 0; /**<To Calculate Vin*/ float Avg; /**<To Calculate the average*/ //For the duration of the program while(1) { Avg = 0; // Clear the average //Take 128 samples for the average for(i=0; i<128; i++) { adcGo(); //Start the ADC low = ADRESL; //Retrieve the ADC values high = ADRESH; high = high << 8; //Combine the high and low values of the ADC Vin = high + low; Vin = (Vin / 1024) * 5; //Scale the ADC Values w.r.t +5V Avg = Avg + Vin ; } Avg = Avg / 128; //Divide the average by its width i Avg = Avg * 4; //Convert Vin due to voltage divider circuit //Displays the voltage on the 2nd line and truncates decimal places lcd_Display(Avg); lcd_goto(0x46); lcd_puts(" Volts"); } }
void deger_goster(unsigned int ham) { unsigned int volt=0; volt=(float)(ham/2.86978)*10; lcd_goto(1,1); lcd_puts("10 Bit = "); integer_yaz(ADC10MEM,0); lcd_goto(2,1); lcd_puts("Gerilim = "); integer_yaz(volt,1); }
/*! \details Load the user-defined symbol into the CGRAM memory. */ void lcd_loadchar(uint8_t* vector, uint8_t position) { uint8_t i; /* Go to the CGRAM memory space: 0 to 7 */ lcd_goto(CGRAM, (position * FONT_HEIGHT)); for(i = 0u; i < FONT_HEIGHT; i++) {/* Load one row of pixels into the CGRAM register. */ lcd_putc(vector[i]); } /* Return to the DDRAM memory space. */ lcd_goto(LCD_1st_LINE, 0u); }
void printPresetMenu(void) { lcd_goto(1, 2); lcd_print("Bank Num "); lcd_print(saveLoad ? "Save" : "Load"); lcd_goto(1, 1); lcd_command(curBank + 'A', 1); if (curPreset < 10) lcd_print(" "); lcd_printnbr(curPreset); lcd_print("-"); lcd_print(" "); lcd_goto(5, 1); printName(&presets[curBank][curPreset][14]); }
void DBUF_Handler(void) { // Handle display communication updates I2CM_Handler(); // Only continue if the display isn't idle or in error if (!(I2CM_state == I2CM_IDLE) && !(I2CM_state == I2CM_ERROR_NAK)) { return; } // Handle buffer to display switch (LCDM_State) { case LCD_GOTO_LINE1_ORIGIN: lcd_goto(0, 0); LCDM_State++; // Go to LCD_UPDATE_LINE_1; break; case LCD_UPDATE_LINE_1: // Popup or normal display on line 1 if (DisplayPopupState & 0x01) { // Popup lcd_putstr(&DisplayPopupBuffer[0], 16); } else { //Normal lcd_putstr(&DisplayBuffer[0], 16); } LCDM_State++; // Go to LCD_GOTO_LINE2_ORIGIN; break; case LCD_GOTO_LINE2_ORIGIN: lcd_goto(0, 1); LCDM_State++; // Go to LCD_UPDATE_LINE_2; break; case LCD_UPDATE_LINE_2: // Same as above for line 2 if (DisplayPopupState & 0x02) { lcd_putstr(&DisplayPopupBuffer[16], 16); } else { lcd_putstr(&DisplayBuffer[16], 16); } LCDM_State++; // Go to LCD_BUSY; break; case LCD_BUSY: // Wait for the update of line 2 to complete LCDM_State++; // Go to LCD_DONE; break; case LCD_DONE: // Idle/Done - Use this state to wait for LCD to complete operation LCDM_State = LCD_GOTO_LINE1_ORIGIN; break; } }
void jfolo(unsigned char count){ unsigned char junction_count=0; unsigned char timer=0; Forward(); // set motor move forward // sending display to lcd takes long time // junction reading and display less frequent. // use timer variable to count 20, then read once. while(junction_count<count){ //second junction timer++; if(timer>50){ timer=0; //clear timer motor(0,0); //slow down for lcd display do{ junction_count=LSA08_GetJunction(); //check junction count }while(ERR_FLAG||(junction_count>10)); //checking no uart error lcd_goto(0); lcd_putchar('J'); lcd_num(junction_count,3); } line_follow(); //PID line follow } Brake(); __delay_ms(200); }
/*! \details Writes ANSI-C string to LCD (DDRAM memory space). */ void lcd_puts(const uint8_t *str) { /* Send a ANSI-C string to LCD. */ while ('\0' != *str) { #if ( USE_FORMATTED_OUTPUT ) if(('\n' == *str)) {/*New line */ lcd_goto(LCD_2nd_LINE, 0u); } else if(('\r' == *str)) {/* Return home */ lcd_return(); } else if(('\t' == *str)) {/* Tab space */ uint8_t i; for(i=0u; i<TAB_SPACE; i++) {/* Shift cursor to the right. */ cursor_shift(RIGHT); } } else #endif { /* Display a symbol. */ lcd_putc(*str); } /* Get the next symbol. */ str++; } }
void log_init(void) { fprintf(stream_wireless,"# initializing logging\r\n"); lcd_clear(); printf(lcd_putch,"Resetting Log!"); delay_ms(1200); write_ext_fram(FRAM_ADDR_RECORD_N,0); write_ext_fram(FRAM_ADDR_DATAFLASH_PAGE+0,0); write_ext_fram(FRAM_ADDR_DATAFLASH_PAGE+1,0); /* erase the first block of the data flash */ dataflash_select(); spi_write2(0x50); spi_write2(0x00); spi_write2(0x00); spi_write2(0x00); dataflash_unselect(); delay_ms(10); /* wait for page to finish erasing and writing */ while ( ! bit_test(dataflash_read_status(),7) ) { restart_wdt(); //fputc('x',modem); } lcd_goto(LCD_LINE_TWO); printf(lcd_putch,"Done"); fprintf(stream_wireless,"> done\r\n"); delay_ms(1200); }
//=============================================================================== // Main Program //=============================================================================== void main(void) { //clear data port PORTA = 0; PORTB = 0; PORTC = 0; // Initialize the I/O port direction. TRISA = 0b00000000; TRISB = 0b00000001; //setup ADC ADCON1 = 0b00000110; //All AN pin become digital pin LED=0; //LED is not activated initially // LCD in 4-bit mode //----------------------------------- lcd_init(); //Initialize LCD lcd_set_cursor(1,0); //Set cursor to column 1, line 1 lcd_putstr("Cytron"); //Display Cytron lcd_goto(0x40); //Set cursor to 2nd line using another function lcd_putstr("SK28A :)"); //Display SK28A while(1) { LED ^= 1; // toggle LED on SK28A delay_ms(50); //delay for around 50ms while(SW1==0)LED = 0; //Halt and Off LED when SW1 is press, continue the program when SW1 is released or not pressed } while(1); //infinate loop to prevent the program to reset at the end of main }
char menu(void) { static unsigned char position = 0; unsigned char item = 0; unsigned char i; while (1) { if (position == MENU_LENGTH) position = 0; for (i = 0; i < LCD_LINES; i++) { lcd_goto(i + 1, 1); item = (position + i > MENU_LENGTH - 1) ? 0 : position + i; if (i == 0) lcd_write_pgm("\002"); else lcd_write_pgm(" "); lcd_write_pgm(menu_items[item]); } position++; while (PORTEbits.RE2 == 1); Delay10KTCYx(255); } return 0; }
void lcd_indicate(char test) { lcd_goto(0x0D); __delay_us(50); lcd_putch(test); __delay_ms(500); }
unsigned char menu(void) { static unsigned char position = 0; unsigned char item = 0; unsigned char i; if (position == MENU_LENGTH) // reset position if the end of menu is reached position = 0; for (i = 0; i < LCD_LINES; i++) { // set the line for item display lcd_goto(i + 1, 1); // enable continuous rotation of items // i.e. item 1 follows the last item in the list item = (position + i > MENU_LENGTH - 1) ? 0 : position + i; if (i == 0) // add an arrow to indicate current menu item lcd_write_pgm("\002"); else // add a space to keep items aligned lcd_write_pgm(" "); // display menu item lcd_write_pgm(menu_items[item]); } // return current position and increment counter for the next call return position++; }
void prvLcdShow( void *pvParameters ) { uint8_t symb, buffer_cnt=0, el_in_queue=0; portBASE_TYPE xStatus; while(1){ el_in_queue = uxQueueMessagesWaiting(xQueueLCD); if(el_in_queue > 0){ if(xSemaphoreTake(xLcdMutex, portMAX_DELAY) == pdPASS){ while(el_in_queue > 0){ if(xQueueReceive(xQueueLCD, &symb, 0) == pdPASS){ if (buffer_cnt == 32){ lcd_clrscr(); buffer_cnt = 0; } if(buffer_cnt == 16){ lcd_goto(2,0); } lcd_putc(symb); buffer_cnt++; el_in_queue--; } } xSemaphoreGive(xLcdMutex); } } } }
void main(void) { int mesure=150; init(); // voir plus haut lcd_goto(0); //lcd d�but 1�re ligne sprintf(chaine,"%s","Valeur mesuree"); lcd_puts(chaine); mesure=mesure*1.236; lcd_goto(0x40); //lcd origine seconde ligne : 40h = 64d sprintf(chaine,"%4d",mesure); //affichage sur 4 digits en d�cimal lcd_puts(chaine); lcd_putch(' '); sprintf(chaine,"%s"," grammes"); lcd_puts(chaine); while (1){ } }
void AddSymblsToList(){ c8=0; i8=0; l8=0; if(f_open(&Fil, _symbfilename, FA_OPEN_EXISTING | FA_READ) == FR_OK){ if(DEBUGSTTS) printf("Card FOUND!!\n\r"); lcd_clrscr(); lcd_puts_E(lcdfnd, 0); lcd_goto(64); lcd_puts(_symbfilename, 0); ///< Fetch symbols and their short names. do{ f_read(&Fil, &msg1, 1, &bw); if (msg1[0]<0x20){l8=1; c8=0;} else if(msg1[0]>0x7E){l8=1; c8=0;} else if(msg1[0]==0x20){ do{ f_read(&Fil, &msg1, 1, &bw); }while (msg1[0]>0x1F && bw++); } ///< Catch comments else if(!bw){ break; } else if(msg1[0]==0x3B){ ///< Encountered ";". Fetch short name. for(c8=0; c8<SHNAMELEN; c8++){ f_read(&Fil, &msg1, 1, &bw); if (msg1[0]<0x21){ break; } else if(msg1[0]>0x7E){ break; } else if(!bw){ break; } else { Symbols[(SYMBOLLEN*MAXSYMBLS)+ (i8*SHNAMELEN)+c8]=msg1[0]; } ///< Make _SURE_ there is nothing left on this line before going back to the normal loop (You can write comments) }if(!msg1[0]<0x20){ do{ f_read(&Fil, &msg1, 1, &bw); }while (msg1[0]>0x1F && bw++); } l8=1; ///< Trigger the new line mechanism. }else{ if(l8){ i8++; l8=0; c8=0; } if(i8>15){ i8=15; break; } Symbols[(i8*SYMBOLLEN)+c8]=msg1[0]; c8++; } } while (bw++ && i8 < 16); Nosymbols=i8+1; }else{ ///< Card not found, Use predefined symbols. #ifdef AVR eeprom_read_block(Symbols, EEP_Symbs, (MAXSYMBLS*SYMBOLLEN)+(SHNAMELEN*MAXSYMBLS)); #else for (l8=0; l8<((MAXSYMBLS*SYMBOLLEN)+(SHNAMELEN*MAXSYMBLS)); l8++){ Symbols[l8]=EEP_Symbs[l8]; } #endif } if(printstats){ for(i8=0; i8<Nosymbols; i8++){ printf("%02d: ", i8+1); printf("%.24s: ", &Symbols[SYMBOLLEN*i8]); printf(" (%.3s)\n", &Symbols[(SYMBOLLEN*MAXSYMBLS)+(SHNAMELEN*i8)]); } } if(printstats) printf("\n\n"); f_close(&Fil); }
//------------------------------- void lcd_load(int8u_t* vector, int8u_t position) {/* USE CGRAM CHAR SPACE: 0 to 7 */ int8u_t i; lcd_goto(CGRAM,position*DRAW_CHAR_SIZE); for(i=0;i<DRAW_CHAR_SIZE;i++) lcd_putc(vector[i]); }
void disp(float num) { int x1,x2,x3,x4,n,temp; static float f1; char ch1,ch2,ch3,ch4,dot='.'; n=num; temp=num; x1=n%10; n=n/10; x2=n%10; if(x2 >= 4) { RB0=1; } else { RB0=0; } n=n/10; x3=n%10; f1=num-temp; x4=f1*10; ch1=lookup(x3); ch2=lookup(x2); ch3=lookup(x1); ch4=lookup(x4); lcd_goto(0); lcd_putch(ch1); lcd_putch(ch2); lcd_putch(ch3); lcd_putch(dot); lcd_putch(ch4); lcd_puts(" deg celsu"); }
void main() // main program begins { unsigned int x,y,c=0x100,z,i; float p,tmpr,f; lcd_init(); ADCON0=0; //ADC channel-1 (AN0) is selected,A/D clock=Fosc/4 TRISA=1; ADCON1=0xCE; //RA0 configured as ananlog (AN0),A/D result Right justified,A/D clock=Fosc/4 ADCON0=ADCON0|1; //ADC is turned on /**********************************************/ lcd_goto(0); lcd_puts(" Welcome"); DelayMs(3000); //pause a second ADCON0=ADCON0|4; //A/D conversion begins i=0; while(i++ < 1000) { if(ADCON0==0x01) break; } //A/D conversion ends x=ADRESH; //ADC result higher 2 bits y=ADRESL; //ADC result lower 8 bits PIR1=PIR1&~64; //ADC interrupt flag is cleared z=x*c+y; //combined 10 bit number formation f=z; //unsigned to float conversion p=(f*5)/1023; //equivalent voltage calculation from ADC output tmpr=p*100; //sensor output voltage to degree Celsius conversion if(tmpr > 25.0) { TRISB=0x10; } else { TRISB=0x00; } disp(tmpr); //call of disp(float) to display the temperature DelayMs(1000); //pause a second /***********************************************/ while(1) //infinite loop { ADCON0=ADCON0|4; //A/D conversion begins i=0; while(i++ < 10000) { if(ADCON0==0x01) break; } //A/D conversion ends x=ADRESH; //ADC result higher 2 bits y=ADRESL; //ADC result lower 8 bits PIR1=PIR1&~64; //ADC interrupt flag is cleared z=x*c+y; //combined 10 bit number formation f=z; //unsigned to float conversion p=(f*5)/1023; //equivalent voltage calculation from ADC output tmpr=p*100; //sensor output voltage to degree Celsius conversion disp(tmpr); //call of disp(float) to display the temperature DelayMs(1000); //pause a second } } //main program ends
/******************************************************************************* * MAIN FUNCTION * *******************************************************************************/ int main(void) { // ensure all the hardware port in zero initially PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; // Initialize the I/O port direction, this must be configured according to circuit // please refer to PTK40A schematic for details // TRISX control pin direction, output pin must be configure as '0' // while input must be configure as '1' TRISA = 0b00010001; TRISB = 0b00001111; TRISC = 0b10010011; TRISD = 0; TRISE = 0; // Initialize ADC. adc_initialize(); //Ensure pin share with analog is being configured to digital correctly // Initialize 7 segments seg7_initialize(); //Ensure 7 segment is blank at beginning // Initialize LCD lcd_initialize(); // LCD must be initialize before it can be use // after initialize, the black rectangular on LCD will disappear beep (2); // buzzer sound twice LCD_BACKLIGHT = 1; //activate LCD backlight // PTK40A is using 2x16 parallel LCD, it is interface in 8-bit mode // Require 10 digital pin to send message to LCD // Please refer to PTK40A schematic for the connection from PIC and lcd.c for the function details // Press SW1 to display "Hello World" to LCD while (SW1 == 1) continue; //wait for SW1 to be press lcd_goto(0x01); // move LCD cursor to 2nd column lcd_putstr("Cytron PTK40A"); // display string at 1st row lcd_goto(0x42); // move LCD cursor to 2nd row, 3rd column lcd_putstr("Hello World"); // display hello world at 2nd row while(1) continue; // infinite loop to prevent PIC from reset if there is no more program }
void update_menu(void) { lcd_goto(1, 1); lcd_print(" "); lcd_goto(1, 2); lcd_print(" "); lcd_goto(1, 1); if (cur_menu == 8) printPresetMenu(); else if (cur_menu == 9) validPresetMenu(); else if (cur_menu == 10) validSavePreset(); else { lcd_print(print_menu[cur_menu]); lcd_goto(1, 2); printmenu_tab[cur_menu][0](params_tab[cur_menu][0]); lcd_goto(5, 2); printmenu_tab[cur_menu][1](params_tab[cur_menu][1]); lcd_goto(9, 2); printmenu_tab[cur_menu][2](params_tab[cur_menu][2]); lcd_goto(13, 2); printmenu_tab[cur_menu][3](params_tab[cur_menu][3]); } }
//------------------------------- void lcd_drawchar( int8u_t* vector, int8u_t position, int8u_t line, int8u_t address ) {/* USE CGRAM CHAR SPACE */ lcd_load(vector,position); lcd_goto(line,address); lcd_putc(position); }