void main() { int v1,v2,v3,x1,x2,i; char txt[7]; lcd_init(); lcd_cmd(_lcd_clear); // clear lcd lcd_cmd(_lcd_cursor_off ); lcd_out(1,1,"Sun Tracker"); trisc=0b00000000; trisd=0b00000011; while(1) { delay_ms(200); v1=adc_read(1); v2=adc_read(2); v3=adc_read(3); i=adc_read(4)*150; x1=v2-v1; x2=v2-v3; inttostr(i,txt); lcd_out(2,1,"I= "); lcd_out(2,4,txt); lcd_out_cp(" uA"); while(i>=1500) { en=0; lcd_out(2,1,"Motor Off "); delay_ms(2000); i=adc_read(4)*150; } if(rd0_bit==0) { en=1; in1=1; in2=0; while(rd1_bit==1); en=0; in1=0; in2=0; } if(x1<-20) { en=1; in1=1; in2=0; } else if(x2<-20) { in1=0; in2=1; en=1; } else { en=0; } } }
void main() { char txt[16]; trisc=0; portc=0; Keypad_Init(); Lcd_Init(); Lcd_Cmd(_LCD_CLEAR); Lcd_Cmd(_LCD_CURSOR_OFF); while(1){ lcd_out(1,1,"EnterTemp="); x=0; do{ kp = 0; kp = Keypad_Key_Click(); } while(!kp); switch (kp) { case 1: kp = 49;previous_value=1;break; // 1 case 2: kp = 50;previous_value=2;break; // 2 case 3: kp = 51;previous_value=3;break; // 3 case 4: kp = 65;break;// A case 5: kp = 52;previous_value=4;break;// 4 case 6: kp = 53;previous_value=5;break; // 5 case 7: kp = 54;previous_value=6;break; // 6 case 8: kp = 66;break; // B case 9: kp = 55;previous_value=7;break; // 7 case 10: kp = 56;previous_value=8;break; // 8 case 11: kp = 57;previous_value=9;break; // 9 case 12: kp = 67;break; // C case 13: kp = 42;break; // * case 14: kp = 48;previous_value=0;break;// 0 case 15: kp = 35;break; // # case 16: kp = 68;break; // D } if(kp==42&&x==0){ //clear the screen lcd_cmd(_lcd_clear); shift=10; first=1000; second=1000; third=1000; desired_temp=0; previous_value=0; get_temp=0; real_temp=0; kp=0; x=1; } if(first==1000&&second==1000&&third==1000&&kp!=35&&x==0){ first=previous_value; shift++; lcd_chr(1,shift,kp); } else if(first!=1000&&second==1000&&third==1000&&kp!=35&&x==0){ second=previous_value; shift++; lcd_chr(1,shift,kp); } else if(first!=1000&&second!=1000&&third==1000&&kp!=35&&x==0){ third=previous_value; shift++; lcd_chr(1,shift,kp); } if(kp==35&&x==0){ shift++; lcd_chr(1,shift,kp); delay_ms(1000); if(first!=1000&&second==1000&&third==1000){ desired_temp=first; } else if(first!=1000&&second!=1000&&third==1000){ first=first*10; desired_temp=first+second; } else if(first!=1000&&second!=1000&&third!=1000){ first=first*100; second=second*10; desired_temp=first+second+third; } while(kp==35&&x==0){ lcd_cmd(_lcd_clear); get_temp=adc_read(0); real_temp=(500.0*get_temp)/1023; inttostr(real_temp,txt); lcd_out(2,1,"RealTemp="); lcd_out_cp(txt); while(real_temp>desired_temp){ get_temp=adc_read(0); real_temp=(500.0*get_temp)/1023; inttostr(real_temp,txt); lcd_out(2,1,"RealTemp="); lcd_out_cp(txt); ac_fan=1; lcd_out(1,1,"cooling"); } while(real_temp<=desired_temp){ get_temp=adc_read(0); real_temp=(500.0*get_temp)/1023; inttostr(real_temp,txt); lcd_out(2,1,"RealTemp="); lcd_out_cp(txt); ac_fan=0; lcd_out(1,1,"process done"); lcd_out(2,1,"RealTemp="); lcd_out_cp(txt); } } } } }
void main() { unsigned char i; unsigned char tmp; unsigned int tmpi; char str[6]; ADCON1=0x06; TRISA=0xC3; TRISB=0x01; TRISC=0x01; TRISD=0x00; TRISE=0x00; RBPU_bit=0; lcd_init(); i2c1_init(10000); adc_init(); /* //dip TRISB=0x03; lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp("Ligue todos DIP"); lcd_cmd(_LCD_SECOND_ROW); lcd_out_cp("Press. RB1"); while(RB1_bit); */ //dip TRISB=0x03; lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp("Desl. RTC e REL1"); lcd_cmd(_LCD_SECOND_ROW); lcd_out_cp("Press. RB1"); while(RB1_bit); //teste TEMP lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp(" Teste TEMP"); TRISA=0x07; ADCON1=0x02; for(i=0; i< 100; i++) { tmpi=(adc_read(2)*10)/2; lcd_cmd(_LCD_SECOND_ROW+5); inttostr(tmpi,str); lcd_chr_cp(str[3]); lcd_chr_cp(str[4]); lcd_chr_cp(','); lcd_chr_cp(str[5]); lcd_chr_cp('C'); delay_ms(20); } //teste Aquecimento lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp(" Teste AQUEC"); RC5_bit=1; for(i=0; i< 100; i++) { tmpi=(adc_read(2)*10)/2; lcd_cmd(_LCD_SECOND_ROW+5); inttostr(tmpi,str); lcd_chr_cp(str[3]); lcd_chr_cp(str[4]); lcd_chr_cp(','); lcd_chr_cp(str[5]); lcd_chr_cp('C'); delay_ms(50); } RC5_bit=0; //teste Resfriamento TRISC0_bit=1; lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp(" Teste RESFR"); //timer0 temporizador T0CS_bit=0; PSA_bit=0; T08BIT_bit=1; T0PS0_bit=0; // divide por 32 T0PS1_bit=0; T0PS2_bit=1; TMR0ON_bit=1; T0IE_bit=1; //T = 32x250x125 = 1segundo; //timer1 contador TMR1CS_bit=1; T1CKPS1_bit=0; T1CKPS0_bit=0; T0IF_bit=0; TMR0H=0; TMR0L=6; //250 cnt=125; GIE_bit=1; TMR1H=0; TMR1L=0; TMR1ON_bit=1; RC2_bit=1; for(i=0; i< 150; i++) { tmpi=(adc_read(2)*10)/2; lcd_cmd(_LCD_SECOND_ROW+2); inttostr(tmpi,str); lcd_chr_cp(str[3]); lcd_chr_cp(str[4]); lcd_chr_cp(','); lcd_chr_cp(str[5]); lcd_chr_cp('C'); lcd_cmd(_LCD_SECOND_ROW+8); inttostr(t1cont,str); lcd_chr_cp(str[2]); lcd_chr_cp(str[3]); lcd_chr_cp(str[4]); lcd_chr_cp(str[5]); lcd_chr_cp('R'); lcd_chr_cp('P'); lcd_chr_cp('S'); delay_ms(30); } GIE_bit=0; RC2_bit=0; ADCON1=0x06; TRISC=0x18; //teste RTC lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp("Teste RTC"); //ajuste rtc_w(); // rtc_w(); rtc_r(); lcd_cmd(_LCD_SECOND_ROW); lcd_out_cp(date); delay_ms(2000); for(i=0;i<20;i++) { rtc_r(); lcd_cmd(_LCD_SECOND_ROW);; lcd_out_cp(time); delay_ms(500); } //dip TRISB=0x03; lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp("Des. DIS* e LED1"); lcd_cmd(_LCD_SECOND_ROW); lcd_out_cp("Press. RB1"); while(RB1_bit); TRISB=0xF8; //teste Teclado lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW+2); lcd_out_cp("Teste Teclado"); lcd_cmd(_LCD_SECOND_ROW+1); i=0; while(i<14) { TRISD=0x0F; tmp=tc_tecla(1500)+0x30; TRISD=0x00; lcd_chr_cp(tmp); i++; } TRISB=0x03; //teste EEPROM INT lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp("Teste EEPROM INT"); // testar ? lcd_cmd(_LCD_SECOND_ROW); lcd_out_cp(" (s=RB0 n=RB1) ?"); // TRISB=0x03; while(RB0_bit && RB1_bit); if(RB0_bit == 0) { tmp=eeprom_read(10); lcd_chr_cp(tmp); eeprom_write(10,0xA5); eeprom_write(10,0x5A); i=eeprom_read(10); eeprom_write(10,tmp); lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp("Teste EEPROM INT"); lcd_cmd(_LCD_SECOND_ROW); if(i == 0x5A) lcd_out_cp(" OK"); else lcd_out_cp(" ERRO"); delay_ms(1000); } else { while(RB1_bit == 0); } //teste EEPROM EXT lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp("Teste EEPROM EXT"); // testar ? lcd_cmd(_LCD_SECOND_ROW); lcd_out_cp(" (s=RB0 n=RB1) ?"); TRISB=0x03; while(RB0_bit && RB1_bit); if(RB0_bit == 0) { tmp=e2pext_r(10); lcd_chr_cp(tmp); e2pext_w(10,0xA5); e2pext_w(10,0x5A); i=e2pext_r(10); e2pext_w(10,tmp); lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp("Teste EEPROM EXT"); lcd_cmd(_LCD_SECOND_ROW); if(i == 0x5A) lcd_out_cp(" OK"); else lcd_out_cp(" ERRO"); delay_ms(1000); } else { while(RB1_bit == 0); } // TRISB=0x00; // PORTB=0; //fim teste lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp(" Fim"); lcd_cmd(_LCD_SECOND_ROW); lcd_out_cp(" Pressione RST"); while(1); }
void main() { char r; Lcd_Init(); INTCON=0b11000000; PIE1=0b00100000; UART1_Init(9600); // Initialize UART module at 9600 bps Delay_ms(300); adcon1=7; trisa=0; porta=0; TRISD=0; PORTD=0b11111111; //portd.f6=0; //GPS Rx portd.f0=0; //GSM TX TRISC=0; portd.f3=0; //zigbee Rx portc.f4=1; delay_ms(2000); TRISC=255; delay_ms(2000); lcd_cmd(_LCD_CURSOR_OFF); for(;;){ if(mode==0) { hr[0]=rr/100+48; rem=rr%100; hr[1]=rem/10+48; hr[2]=rem%10+48; lcd_out(1,1,hear); lcd_out_cp(hr); //lcd_chr(2,1,rr); } if(mode==1) { PORTD=0b11111111; portd.f0=0; //GSM TX portd.f6=0; //GPS Rx lcd_cmd(_LCD_CLEAR); porta.f1=1; delay_ms(500); porta.f1=0; mode=2; while(v<6) { } delay_ms(2000); lcd_chr(1,1,rec[14]); for (r=15;r<23;r++){ lcd_chr_cp(rec[r]); } lcd_chr(2,1,rec[26]); for (r=27;r<36;r++){ lcd_chr_cp(rec[r]); } delay_ms(2000); UART1_WRITE_TEXT("AT+CMGF=1"); UART1_WRITE(13); delay_ms(300); UART1_WRITE_TEXT(we); delay_ms(300); UART1_WRITE_TEXT("Latu:"); for (r=14;r<23;r++){ UART1_WRITE(rec[r]); } //UART1_WRITE(10); UART1_WRITE(13); UART1_WRITE_TEXT("Long:"); delay_ms(300); for (r=26;r<36;r++){ UART1_WRITE(rec[r]); } UART1_WRITE(13); delay_ms(300); UART1_WRITE(26); delay_ms(1000); } } }
void main() { unsigned char i; unsigned char tmp; unsigned int tmpi; unsigned int tout; char str[6]; ADCON1=0x06; TRISA=0xC3; TRISB=0x01; TRISC=0x01; TRISD=0x00; TRISE=0x00; NOT_RBPU_bit=0; lcd_init(); UART1_Init(9600); adc_init(); /* //dip TRISB=0x03; lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp(codetxt_to_ramtxt("Ligue todos DIP")); lcd_cmd(_LCD_SECOND_ROW); lcd_out_cp(codetxt_to_ramtxt("Press. RB1")); while(RB1_bit); */ //testa caracter especial lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp(codetxt_to_ramtxt(" Teste LCD")); lcd_cmd(0x40);//endere�o lcd_chr_cp(0x11); lcd_chr_cp(0x19); lcd_chr_cp(0x15); lcd_chr_cp(0x13); lcd_chr_cp(0x13); lcd_chr_cp(0x15); lcd_chr_cp(0x19); lcd_chr_cp(0x11); lcd_chr_cp(0x0E); lcd_chr_cp(0x11); lcd_chr_cp(0x0E); lcd_chr_cp(0x05); lcd_chr_cp(0x0E); lcd_chr_cp(0x14); lcd_chr_cp(0x0A); lcd_chr_cp(0x11); lcd_cmd(_LCD_SECOND_ROW); for(i=0;i<16;i++) { lcd_chr_cp(i%2); delay_ms(100); } //teste lcd lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp(codetxt_to_ramtxt(" Teste LCD")); for(i=32;i<128;i++) { if((i%16) == 0)lcd_cmd(_LCD_SECOND_ROW); lcd_chr_cp(i); delay_ms(50); } delay_ms(100); lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp(codetxt_to_ramtxt(" Teste LCD")); lcd_cmd(_LCD_SECOND_ROW); lcd_out_cp(codetxt_to_ramtxt(" Ok")); delay_ms(500); //testa display 7s lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp(codetxt_to_ramtxt(" Teste 7 Seg")); ADCON1=0x06; for(i=0;i<4;i++) { switch(i) { case 0: PORTA=0x20; break; case 1: PORTA=0x10; break; case 2: PORTA=0x08; break; case 3: PORTA=0x04; break; } for(tmp=0;tmp<16;tmp++) { PORTD=display7s(tmp); delay_ms(200); } } ADCON1=0x02; PORTD=0; /* //dip TRISB=0x03; lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp(codetxt_to_ramtxt("Desligue RTC DIP")); lcd_cmd(_LCD_SECOND_ROW); lcd_out_cp(codetxt_to_ramtxt("Press. RB1")); while(RB1_bit); */ //testa LEDs TRISB=0x00; lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW+3); lcd_out_cp(codetxt_to_ramtxt("Teste LEDs")); for(tmp=0;tmp<3;tmp++) { for(i=1;i > 0;i=i*2) { PORTB=i; PORTD=i; delay_ms(200); } } PORTB=0; PORTD=0; for(i=0;i<4;i++) { PORTB^=0xFF; PORTD^=0xFF; delay_ms(200); } //testa chaves lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp(codetxt_to_ramtxt(" Teste Chaves")); tmp=0; ADCON1=0x06; TRISA|=0x20; while((tmp & 0x7F) != 0x7F) { TRISB=0x3F; if(RB0_bit == 0) { tmp|=0x01; } if(RB1_bit == 0) { tmp|=0x02; } if(RB2_bit == 0) { tmp|=0x04; } if(RB3_bit == 0) { tmp|=0x08; } if(RB4_bit == 0) { tmp|=0x10; } if(RB5_bit == 0) { tmp|=0x20; } if(RA5_bit == 0) { tmp|=0x40; } TRISB=0x00; PORTB=tmp; delay_ms(10); } delay_ms(500); PORTB=0; ADCON1=0x02; TRISC7_bit=1; //RX TRISC6_bit=0; //TX //teste serial lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp(codetxt_to_ramtxt("Teste Serial TX")); lcd_cmd(_LCD_SECOND_ROW+4); lcd_out_cp(codetxt_to_ramtxt("9600 8N1")); uart1_write_text(codetxt_to_ramtxt("\r\n Picsimlab\r\n Teste Serial TX\r\n")); for(i=0;i<4;i++) { uart1_write(i+0x30); uart1_write_text(codetxt_to_ramtxt(" PicsimLab\r\n")); } delay_ms(1000); lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp(codetxt_to_ramtxt("Teste Serial RX")); uart1_write_text(codetxt_to_ramtxt(" Digite!\r\n")); for(i=0;i<32;i++) { if(!(i%16)) { lcd_cmd(_LCD_SECOND_ROW); uart1_write_text(codetxt_to_ramtxt("\r\n")); } tout=0; while((!uart1_data_ready())&&(tout<2000)) { tout++; delay_ms(1); } if(uart1_data_ready()) { tmp=uart1_read(); } else { tmp='-'; } lcd_chr_cp(tmp); uart1_write(tmp); } delay_ms(100); //teste ADC lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp(codetxt_to_ramtxt(" Teste ADC (P1)")); for(i=0; i< 200; i++) { tmp=(adc_read(0)*10)/204; lcd_cmd(_LCD_SECOND_ROW+6); inttostr(tmp,str); if(str[4] == ' ') lcd_chr_cp('0'); else lcd_chr_cp(str[4]); lcd_chr_cp(','); lcd_chr_cp(str[5]); lcd_chr_cp('V'); delay_ms(10); } lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp(codetxt_to_ramtxt(" Teste ADC (P2)")); for(i=0; i< 200; i++) { tmp=((unsigned int)adc_read(1)*10)/204; lcd_cmd(_LCD_SECOND_ROW+6); inttostr(tmp,str); if(str[4] == ' ') lcd_chr_cp('0'); else lcd_chr_cp(str[4]); lcd_chr_cp(','); lcd_chr_cp(str[5]); lcd_chr_cp('V'); delay_ms(10); } //teste RELE TRISC0_bit=0; TRISE0_bit=0; lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp(codetxt_to_ramtxt("Teste RELE 1 2")); for(i=0;i<5;i++) { RC0_bit^=1; RE0_bit^=1; delay_ms(500); } RC0_bit=0; RE0_bit=0; /* lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp(codetxt_to_ramtxt("Teste RELE 2")); for(i=0;i<5;i++) { RE0_bit^=1; delay_ms(500); } RE0_bit=0; */ //fim teste lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_FIRST_ROW); lcd_out_cp(codetxt_to_ramtxt(" Fim")); /* lcd_cmd(_LCD_SECOND_ROW); lcd_out_cp(codetxt_to_ramtxt(" Pressione RST")); */ uart1_write_text(codetxt_to_ramtxt("\r\n FIM!\r\n")); while(1); }