void main(){ float distance = 0; OUTPUT_LOW(LCD_RW); LCD_Init(); LCD_PutCmd(0x01); SETUP_TIMER_1(T1_INTERNAL|T1_DIV_BY_4); SETUP_CCP1(CCP_CAPTURE_RE); ENABLE_INTERRUPTS(INT_CCP1); ENABLE_INTERRUPTS(GLOBAL); while (True){ Trigger(); while (echo == 0){ ; } distance = value*0.8/58; LCD_PutCmd(0x01); LCD_SetPosition(0x00); LCD_PutChar("Distance:"); LCD_SetPosition(0x40); printf(LCD_PutChar,"%.2fcm",distance); delay_ms(1000); } }
//void Delay(uint32_t dlyTicks); void LCD_Init1 ( void ) //Initialize display { delay (20); /* wait enough time after Vdd rise */ GPIO->P[COM_PORT].DOUTCLR = 1 << LCD_RS ; //LCD_RS=0; GPIO->P[COM_PORT].DOUTSET = 1 << LCD_D4 ; //LCD_D4=1; GPIO->P[COM_PORT].DOUTSET = 1 << LCD_D5 ; //LCD_D5=1; GPIO->P[COM_PORT].DOUTCLR = 1 << LCD_D6 ; //LCD_D6=0; GPIO->P[COM_PORT].DOUTCLR = 1 << LCD_D7 ; // LCD_D7=0; GPIO->P[COM_PORT].DOUTCLR = 1 << LCD_EN ; // LCD_EN=0; //PORTD = 0x03; LCD_PulseEnable(); delay (6); LCD_PulseEnable(); delay (1); LCD_PulseEnable(); GPIO->P[COM_PORT].DOUTCLR = 1 << LCD_RS ; //LCD_RS=1; GPIO->P[COM_PORT].DOUTCLR = 1 << LCD_D4 ; //LCD_D4=0; GPIO->P[COM_PORT].DOUTSET = 1 << LCD_D5 ; //LCD_D5=1; GPIO->P[COM_PORT].DOUTCLR = 1 << LCD_D6 ; //LCD_D6=0; GPIO->P[COM_PORT].DOUTCLR = 1 << LCD_D7 ; //LCD_D7=0; GPIO->P[COM_PORT].DOUTCLR = 1 << LCD_EN ; // LCD_EN=0; //PORTD = 0x02 ; /* set 4-bit interface */ LCD_PulseEnable(); LCD_PutCmd ( 0x2C ); /* function set (all lines, 5x7 characters) */ LCD_PutCmd ( 0x0C ); /* display ON, cursor off, no blink */ LCD_PutCmd ( 0x01 ); /* clear display */ LCD_PutCmd ( 0x06 ); /* entry mode set, increment & scroll left */ }
void main(){ OUTPUT_LOW(LCD_RW); //Che do ghi LCD_Init(); //Khoi tao LCD LCD_PutCmd(0x01); //Xoa man hinh ENABLE_INTERRUPTS(INT_TIMER0); //Kich hoat ngat ngoai SETUP_TIMER_0(RTCC_INTERNAL|RTCC_DIV_32); //Xung kich noi va chia truoc 32 ENABLE_INTERRUPTS(GLOBAL); //Cho phep ngat toan cuc SET_TIMER0(100); //Bat dau dem tu 100, khi tran Timer0 duoc 1ms while (True){ //Duy tri hoat dong cua vi dieu khien if (dem > N_max){ dem = 0; LCD_PutCmd(0x01); } LCD_SetPosition(0x00); //Cot 1 dong 1 LCD_PutChar("Dem so:"); LCD_SetPosition(0x07); //Cot 8 dong 1 printf(LCD_PutChar,"%lu",dem); } }
void main(){ int temp1, temp2,temp3; // Bien duoc do ra tu EEPROM int keypad[10],i, position; int B_ENTER, B_EXIT, E0; temp1 = read_eeprom(add_setup_temp_1); temp2 = read_eeprom(add_setup_temp_2); temp3 = read_eeprom(add_setup_temp_3); nhietdo_setup = temp1*10 + temp2 + temp3*0.1; //Gia tri nhiet do setup Output_low(LCD_RW); LCD_Init(); TRISB = 0xFF; TRISE = 0xFF; LCD_PutCmd(0x01); LCD_SetPosition(0x00); //Chuyen vi tri con tro sang dong 1 printf(lcd_putchar,"Setup: %.1f",nhietdo_setup); lcd_putchar(223); printf(lcd_putchar,"C"); while (true){ //Doc gia tri nhiet do tu cam bien DS18B20 temp_float = ds18b20_read(); LCD_SetPosition(0x40); //Chuyen vi tri con tro sang dong 2 printf(lcd_putchar,"Measure: %.1f",temp_float); lcd_putchar(223); printf(lcd_putchar,"C"); OF_RELAY(temp_float, nhietdo_setup); E0 = input(SETUP_EXIT); if (E0 == 0){ //while (input(SETUP_EXIT)==0) ; LCD_PutCmd(0x01); LCD_SetPosition(0x00); printf(lcd_putchar,"SETUP TEMP: "); delay_ms(1000); i = 0; position = 64; //Khi chua nhan nut EXIT hay ENTER B_EXIT = input(SETUP_EXIT); B_ENTER = input(ENTER); while ((B_ENTER==1) | (B_EXIT == 1)){ int value; B_EXIT = input(SETUP_EXIT); B_ENTER = input(ENTER); value = READ_BUTTON(); //Chi cho nhap va hien thi 3 so if ((value >= 0) && (value < 10) && (i<=2)){ LCD_SetPosition(position); printf(lcd_putchar,"%d",value); delay_ms(1000); keypad[i] = value; i++; position++; } else //Khi da nhap du 3 so va nhan nut ENTER if ((value == 100) && (i>=3)){ write_eeprom(add_setup_temp_1,keypad[0]); write_eeprom(add_setup_temp_2,keypad[1]); write_eeprom(add_setup_temp_3,keypad[2]); temp1 = read_eeprom(add_setup_temp_1); temp2 = read_eeprom(add_setup_temp_2); temp3 = read_eeprom(add_setup_temp_3); nhietdo_setup = temp1*10 + temp2 + temp3*0.1; //Gia tri nhiet do setup LCD_PutCmd(0x01); LCD_SetPosition(0x00); //Chuyen vi tri con tro sang dong 1 printf(lcd_putchar,"Setup: %.1f",nhietdo_setup); lcd_putchar(223); printf(lcd_putchar,"C"); temp_float = ds18b20_read(); LCD_SetPosition(0x40); //Chuyen vi tri con tro sang dong 2 printf(lcd_putchar,"Measure: %.1f",temp_float); lcd_putchar(223); printf(lcd_putchar,"C"); break; } else if (value == 50){ //Khi da nhan nut EXIT thi thoat khoi vong lap LCD_PutCmd(0x01); LCD_SetPosition(0x00); //Chuyen vi tri con tro sang dong 1 printf(lcd_putchar,"Setup: %.1f",nhietdo_setup); lcd_putchar(223); printf(lcd_putchar,"C"); temp_float = ds18b20_read(); LCD_SetPosition(0x40); //Chuyen vi tri con tro sang dong 2 printf(lcd_putchar,"Measure: %.1f",temp_float); lcd_putchar(223); printf(lcd_putchar,"C"); break; } } } } }
int main(void) { chip_configs(); CAPLESENSE_Init(0); GPIO_configs(); UART_init(); LCD_Init1(); lcd_str("connecting",1,3); //TIMER_config(); while(GPIO_PinInGet(COM_PORT, Status)==0); lcd_str("getting time",1,2); time_init(); lcd_str("did it",1,6); choice=1;oc=2; LCD_PutCmd ( 0x01 ); /* clear display */ /* Infinite loop */ menu_t menu1={1,2}; menu_t menu2={2,2}; menu_t menu3={3,2}; menu_t menu4={4,2}; menu_t menu5={5,2}; current=1; //start with menu1 // flags mor manage the interface in their different menus: // unsigned char menu = 1; // 1-> menu1; 2->menu2 // // unsigned char menu1 = 0; //defines the main 2 things to do: 1-> start new task; 2-> show statues of current tasks // unsigned char menu2 = 0; // 1-> start new task: opens the meu in which it is show the time the sch calculates and the options for the user // unsigned char menu3 = 0; // 2-> show status of current tasks: show the id of the task and the time in which it will be excecuted char s1[8]; while (1) { delay(100); menuLCD(menu1, menu2,menu3 , menu4, menu5); // if(completed==1) // if(Recieved) // // { // //getserial(s1); // if(strcmp(Buffer,"off")==0) // GPIO->P[LED_PORT].DOUTCLR = 1 << LED1; // // else if(strcmp(Buffer,"on")==0) // GPIO->P[LED_PORT].DOUTSET = 1 << LED1; // else if(strcmp(Buffer,"blink")==0) // { // GPIO->P[LED_PORT].DOUTCLR = 1 << LED1; // delay(1000); // GPIO->P[LED_PORT].DOUTSET = 1 << LED1; // delay(1000); // GPIO->P[LED_PORT].DOUTCLR = 1 << LED1; // delay(1000); // } else // sendserial("Solar Ranger says: command wasn't recognized :( !!! \n"); // sendserial(Buffer); // completed=0; // } } }