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() { 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() { 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); }