forward(){ trisd=0; ultra3(); intToStr(q,txt); uart1_write_text(txt); while(q>10){ ultra3(); intToStr(q,txt); uart1_write_text(txt); uart1_write_text("loop"); portd=0b01100000; } }
trnlft(){ trisd=0; ultra2(); intToStr(j,txt); uart1_write_text(txt); if(j<10) f2++; while(j>10){ intToStr(j,txt); uart1_write_text(txt); ultra2(); portd=0b10100000; } }
void main() { adcon1=7; uart1_init(9600); delay_ms(4000); trisd=0; uart1_write_text("ready"); portd=0b01100000; for(;;){ trisa=0b00000111; f1=0; f2=0; /*if(porta.f1==1) delay_ms(100);*/ while(porta.f1==1) { trisd=0 ; for(zz=0;zz<10;zz++) { initrit(); delay_ms(200); } while(f1<80) forward(); portd=0; delay_ms(1000); while(f2<40) trnlft(); portd=0; trisa=0; porta=0; } } }
void main() { unsigned int x=0; char txt[7]; char pins; unsigned int clpin[8]; config(); flash(); uart1_init(9600); uart1_write_text("hello"); clpin[0]=touch(0); clpin[1]=touch(1); clpin[2]=touch(2); clpin[3]=touch(3); clpin[4]=touch(8); clpin[5]=touch(9); clpin[6]=touch(10); clpin[7]=touch(12); while(1) { //delay_ms(100); uart1_write_text("pin="); x=touch(2); inttostr(x,txt); uart1_write_text(txt); uart1_write(13); uart1_write_text("pin="); pins=get_touch(clpin); inttostr(pins,txt); uart1_write_text(txt); uart1_write(13); led(pins); } }
trnlft(){ trisd=0; ultra2(); intToStr(j,txt); uart1_write_text(txt); if(j<30) f2++; sum=j; while(sum>30){ sum=0; intToStr(j,txt); uart1_write_text(txt); for(zz=0;zz<10;zz++) { ultra2(); averege[zz]=j; } for(zz=0;zz<10;zz++) sum=sum+averege[zz]; sum=sum/10; portd=0b10100000; } }
void main() { uart1_init(9600); uart1_write_text("ready"); trisd=0 ; // initrit(); for(;;){ forward(); // portd=0; // delay_ms(1000); // ultra2(); // trnlft(); portd=0; } }
void main() { uart1_init(9600); uart1_write_text("ready"); trisd=0 ; for(zz=0;zz<10;zz++) { initrit(); delay_ms(200); } while(f1<50) forward(); portd=0; delay_ms(1000); while(f2<50) trnlft(); portd=0; }
void main() { Lcd_Init(); INTCON=0b11000000; PIE1=0b00100000; UART1_Init(9600); // Initialize UART module at 9600 bps Delay_ms(300); // Wait for UART module to stabilize trisc=0b10000000; portc=255; portc.f1=0; portc.f2=0; trisd=0; uart1_write_text("ready"); for(;;){ if(x==1) { Lcd_Chr_Cp(rr); x=0; } }}
void main() { Lcd_Init(); INTCON=0b11000000; PIE1=0b00100000; UART1_Init(9600); // Initialize UART module at 9600 bps Delay_ms(300); // Wait for UART module to stabilize trisc=0b10000000; trisd=0; portc=255; portc.f0=0; uart1_write_text("ready"); for(;;){ lcd_chr(1,1,rec[14]); for (co=15;co<23;co++){ lcd_chr_cp(rec[co]); } lcd_chr(2,1,rec[26]); for (co=27;co<36;co++){ lcd_chr_cp(rec[co]); } }}
void main() { bit i,j,k,m; int rc; int lc; int x; int y; i=1;j=1;m=1;k=1; uart1_init(9600); lcd_init(); for(;;) { rc=adc_read(1)*0.05; lc=adc_read(0)*0.05; x=adc_read(4)*0.05; y=adc_read(3)*0.05; if(x>=18) { lcd_out(1,1,"X+"); uart1_write_text("x+"); delay_ms(60); } if(x<=15) { lcd_out(1,1,"X-"); uart1_write_text("x-"); delay_ms(60); } if(y>=18) { lcd_out(1,1,"Y+"); uart1_write_text("y+"); delay_ms(60); } if(y<=15) { lcd_out(1,1,"Y-"); uart1_write_text("y-"); delay_ms(60); } if(lc<=7&&k==1) { lcd_out(2,1,"L1"); uart1_write_text("l1"); k=0; m=1; delay_ms(60); } if(lc>=9&&m==1) { lcd_out(2,1,"L2"); uart1_write_text("l2"); m=0; k=1; delay_ms(60); } if(rc<=12&&i==1) { lcd_out(2,1,"r1"); uart1_write_text("r1"); i=0; j=1; delay_ms(60); } if(rc>=14&&j==1) { lcd_out(2,1,"r2"); uart1_write_text("r2"); j=0; i=1; delay_ms(60); } } }
void main() { int i; int temp1; char test[32]; uart1_init(2400); CE_DIR=0; CSN_DIR=0; CSK_DIR=0; MOSI_DIR=0; MISO_DIR=1; delay_ms(500); nrf24_config(); CSN=1; CE=1; lcd_init(); Lcd_Cmd(_LCD_CURSOR_OFF); //lcd_out(2,1,"welcome"); trisb.f0=0; rb0_bit=0; trisd.f0=0; for(i=0;i<30;i++) { rd0_bit=1; delay_us(400); rd0_bit=0; delay_us(19600); } uart1_write_text("TEST"); uart1_write(13); //lcd_out(1,1,"S"); while(1) { temp1=read_add(0x07); if(((temp1&0b01000000)>>6)==1) { CE=0; delay_ms(50); //lcd_out(1,1,"data"); read_buff(0x61,test,32); uart1_write_text(test); lcd_out(1,1,test); reset(); CE=1; } if(uart1_data_ready()) { rfid[idx]=uart1_read(); ///////////////////////////////////////////////////////////03002e2838 if(rfid[idx]=='0'&&valid2<10) { valid2++; } else if(rfid[idx]=='3'&&valid2<10) { valid2++; } else if(rfid[idx]=='2'&&valid2<10) { valid2++; } else if(rfid[idx]=='E'&&valid2==5) { valid2++; } else if(rfid[idx]=='8'&&valid2<10) { valid2++; } else { valid2=0; } if(rfid[idx]=='0'&&valid1<10) //03002e90b0 { valid1++; } else if(rfid[idx]=='3'&&valid1==1) { valid1++; } else if(rfid[idx]=='2'&&valid1==4) { valid1++; } else if(rfid[idx]=='E'&&valid1==5) { valid1++; } else if(rfid[idx]=='9'&&valid1==6) { valid1++; } else if(rfid[idx]=='B'&&valid1==8) { valid1++; } else { valid1=0; } if(valid2>=10) { lcd_out(2,1,"User2 : 03002E2838"); delay_ms(1000); lcd_cmd(_lcd_clear); lcd_out(2,1,"UnValid"); valid2=0; for(i=0;i<30;i++) { rd0_bit=1; delay_us(400); rd0_bit=0; delay_us(19600); } delay_ms(1000); lcd_cmd(_lcd_clear); } if(valid1>=10) { lcd_out(2,1,"User1 : 03002E90B0"); delay_ms(1000); lcd_cmd(_lcd_clear); lcd_out(2,1,"Valid"); valid1=0; for(i=0;i<30;i++) { rd0_bit=1; delay_us(1500); rd0_bit=0; delay_us(18500); } delay_ms(1000); for(i=0;i<30;i++) { rd0_bit=1; delay_us(400); rd0_bit=0; delay_us(19600); } lcd_cmd(_lcd_clear); } } } }
void main() { char error,error2; uart1_init(9600); SPI1_Init(); buf[0]='E'; buf[1]='n'; buf[2]='g'; buf[3]='S'; buf[4]='h'; buf[5]='a'; buf[6]='d'; buf[7]='y'; trisd=255; error = MMC_init(); if(!error){ uart1_write_text("connected"); } else uart1_write_text("not connected"); while(1) { if(rd0_bit==0) { buf[0]='E'; buf[1]='n'; buf[2]='g'; buf[3]='S'; buf[4]='h'; buf[5]='a'; buf[6]='d'; buf[7]='y'; error2 = Mmc_write_Sector(1, buf); if(!error2) { uart1_write_text("write success"); } else uart1_write_text("write not success"); while(rd0_bit==0){} } if(rd1_bit==0) { error2 = Mmc_read_Sector(1, read); uart1_write_text(read); while(rd1_bit==0){} } if(rd2_bit==0) { buf[0]='E'; buf[1]='n'; buf[2]='g'; buf[3]='i'; buf[4]='s'; buf[5]='m'; buf[6]='a'; buf[7]='i'; buf[7]='l'; error2 = Mmc_write_Sector(1, buf); if(!error2) { uart1_write_text("write success"); } else uart1_write_text("write not success"); while(rd2_bit==0){} } } }
void main() { char rec; int x,y; int f[5]; char send[7]; uart1_init(9600); trisc=0b10000000; DI=1; CLK=1; uart1_write_text("hello"); while(1) { if(uart1_data_ready()) { rec=uart1_read(); if(rec=='1') audio(1); if(rec=='2') audio(2); if(rec=='3') audio(3); if(rec=='4') audio(4); if(rec=='5') audio(5); } f[0]=adc_read(12); f[1]=adc_read(10); f[2]=adc_read(8); f[3]=adc_read(9); f[4]=adc_read(11); x=adc_read(0); y=adc_read(1); inttostr(f[0],send); uart1_write_text("f0="); uart1_write_text(send); uart1_write(13); IntToStr(f[1],send); uart1_write_text("f1="); uart1_write_text(send); uart1_write(13); IntToStr(f[2],send); uart1_write_text("f2="); uart1_write_text(send); uart1_write(13); IntToStr(f[3],send); uart1_write_text("f3="); uart1_write_text(send); uart1_write(13); IntToStr(f[4],send); uart1_write_text("f4="); uart1_write_text(send); uart1_write(13); IntToStr(x,send); uart1_write_text("x="); uart1_write_text(send); uart1_write(13); IntToStr(y,send); uart1_write_text("y="); uart1_write_text(send); uart1_write(13); delay_ms(1000); if(f[0]<170&&f[1]<180&&f[2]<180&&f[3]>250) { audio(2); delay_ms(5000); } else if(f[0]<170&&f[1]<180&&f[2]<180&&f[3]<170&&rec!='c') { audio(1); delay_ms(5000); } else if(f[0]>230&&f[1]>230&&f[2]>230&&f[3]>230&&x<280) { audio(3); delay_ms(5000); } else if(f[0]<170&&f[1]<180&&f[2]<180&&f[3]<170&&rec=='c') { audio(4); rec=0; delay_ms(5000); } else if(f[0]>230&&f[1]>230&&f[2]>230&&f[3]>230&&x>350&&rec=='b') { audio(5); rec=0; delay_ms(5000); } } }
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); }