Korawy
Member level 3
- Joined
- Sep 8, 2011
- Messages
- 61
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,288
- Activity points
- 1,776
unsigned int count=0,count1=0,add=0,code=0,code1=0,zer=0,stop=0;
unsigned int co1,co2,co3,co4,co11,co22;
unsigned char y2[3],y3[3];
void check(){
co1=TMR0L;
Delay_ms(100);
co2=TMR0L;
co11=co2-co1;
Inttostr(co11,y2);
Lcd_Out(2,1,y2);
TMR0L=0X00;
co3=TMR1L;
Delay_ms(100);
co4=TMR1L;
co22=co4-co3;
Inttostr(co22,y3);
Lcd_Out(2,8,y3);
TMR1H=0x00;
TMR1L=0x00;}
void receiver(){
TMR3H=0x00;
TMR3L=0X00;
T3CON.F0=1;
while(PORTB.F0==0){}
count=(TMR3H*256)+TMR3L;
count=count/5;
T3CON.F0=0;
if(count>300&&count<800)zer++; }
void receiver0(){
TMR3H=0x00;
TMR3L=0X00;
T3CON.F0=1;
while(PORTB.F0==1){}
count=(TMR3H*256)+TMR3L;
count=count/5;
T3CON.F0=0;
if(count>300&&count<700)code++;
}
void receiver1(){
TMR3H=0x00;
TMR3L=0X00;
T3CON.F0=1;
while(PORTB.F0==1){}
count=(TMR3H*256)+TMR3L;
count=count/5;
T3CON.F0=0;
if(count>900&&count<1400)code1++;
//INttoStr(count1,count_dis);
//LCD_out(2,1,count_dis);
}
void main(){
unsigned int x,y,i,y1,h,h1,i11,i22;
unsigned int x1,i1;
unsigned short d1,d2;
TRISB=0b00000001;
TRISC=0;
TRISD=0;
PORTB=0;
PORTC=0;
T3CON.F7=0;
T3CON.F5=0;
T3CON.F4=0;
T3CON.F1=0;
T3CON.F0=0;
T2CON.F2=1;
T1CON=0b00110110;
T0CON=0b01100101;
TMR2=0;
TMR1H=0x00;
TMR1L=0x00;
TMR0L=0x00;
x=0,y=0,x1=0,y1=0,i=0,h=0,i11=0,i1=1,y1=1,h1=1,i22=1,d1=255,d2=255,co1=0,co2=0,co3=0,co4=0,co11=0,co22=0;
Lcd_Init(&PORTD);
Lcd_Cmd(Lcd_Clear);
LCD_Cmd(Lcd_Cursor_OFF);
LCD_Out(1,1,"robotic vechile");
PWM1_Init(20000);
PWM2_Init(20000);
PWM1_Start();
PWM2_Start();
PWM1_change_duty(d1);
PWM2_change_duty(d2);
T1CON.F0=1;
T0CON.F7=1;
Delay_ms(1000);
for(;;){
loop:
for(x=0;x<50;x++){
for(i=0;i<i1;i++){
code=0,code1=0,zer=0;
if(PORTB.F0==1){ //10010101-1236(527)
receiver1();
if(code1==1){
if(PORTB.F0==0){
receiver();
if(zer==1){
if(PORTB.F0==1){
receiver0();
if(code==1){
if(PORTB.F0==0){
receiver();
if(zer==2){
if(PORTB.F0==1){
receiver0();
if(code==2){
if(PORTB.F0==0){
receiver();
if(zer==3){
if(PORTB.F0==1){
receiver1();
if(code1==2){
if(PORTB.F0==0){
receiver();
if(zer==4){
if(PORTB.F0==1){
receiver0();
if(code==3){
if(PORTB.F0==0){
receiver();
if(zer==5){
if(PORTB.F0==1){
receiver1();
if(code1==3){
if(PORTB.F0==0){
receiver();
if(zer==6){
if(PORTB.F0==1){
receiver0();
if(code==4){
if(PORTB.F0==0){
receiver();
if(zer==7){
if(PORTB.F0==1){
receiver1();
if(code1==4){
if(PORTB.F0==0){
receiver();
if(zer==8){
d1=255;
d2=255;
PORTB.F4=1;
PORTB.F1=1;
PORTB.F2=0;
PORTB.F5=0;
PWM1_change_duty(d1);
PWM2_change_duty(d2);
i1=250;
stop=100;
}}} } }}}}}}}}}}}}}}}}}}}}}}}}}}}}}
for(y=0;y<y1;y++){
code=0,code1=0,zer=0;
if(PORTB.F0==1){ //11011100-1236(527)
receiver1();
if(code1==1){
if(PORTB.F0==0){
receiver();
if(zer==1){
if(PORTB.F0==1){
receiver1();
if(code1==2){
if(PORTB.F0==0){
receiver();
if(zer==2){
if(PORTB.F0==1){
receiver0();
if(code==1){
if(PORTB.F0==0){
receiver();
if(zer==3){
if(PORTB.F0==1){
receiver1();
if(code1==3){
if(PORTB.F0==0){
receiver();
if(zer==4){
if(PORTB.F0==1){
receiver1();
if(code1==4){
if(PORTB.F0==0){
receiver();
if(zer==5){
if(PORTB.F0==1){
receiver1();
if(code1==5){
if(PORTB.F0==0){
receiver();
if(zer==6){
if(PORTB.F0==1){
receiver0();
if(code==2){
if(PORTB.F0==0){
receiver();
if(zer==7){
if(PORTB.F0==1){
receiver0();
if(code==3){
if(PORTB.F0==0){
receiver();
if(zer==8){
d1=255;
d2=255;
PORTB.F2=1;
PORTB.F5=1;
PORTB.F4=0;
PORTB.F1=0;
PWM1_change_duty(d1);
PWM2_change_duty(d2);
y1=250;
stop=100;
}}} } }}}}}}}}}}}}}}}}}}}}}}}}}}}}}
for(h=0;h<h1;h++){
code=0,code1=0,zer=0;
if(PORTB.F0==1){ //00100110-1236(527)
receiver0();
if(code==1){
if(PORTB.F0==0){
receiver();
if(zer==1){
if(PORTB.F0==1){
receiver0();
if(code==2){
if(PORTB.F0==0){
receiver();
if(zer==2){
if(PORTB.F0==1){
receiver1();
if(code1==1){
if(PORTB.F0==0){
receiver();
if(zer==3){
if(PORTB.F0==1){
receiver0();
if(code==3){
if(PORTB.F0==0){
receiver();
if(zer==4){
if(PORTB.F0==1){
receiver0();
if(code==4){
if(PORTB.F0==0){
receiver();
if(zer==5){
if(PORTB.F0==1){
receiver1();
if(code1==2){
if(PORTB.F0==0){
receiver();
if(zer==6){
if(PORTB.F0==1){
receiver1();
if(code1==3){
if(PORTB.F0==0){
receiver();
if(zer==7){
if(PORTB.F0==1){
receiver0();
if(code==5){
if(PORTB.F0==0){
receiver();
if(zer==8){
d2=175;
PORTB.F4=1;
PORTB.F1=1;
PORTB.F2=0;
PORTB.F5=0;
PWM2_change_duty(d2);
h1=250;
stop=100;
}}} } }}}}}}}}}}}}}}}}}}}}}}}}}}}}}
for(i11=0;i11<i22;i11++){
code=0,code1=0,zer=0;
if(PORTB.F0==1){ //11010101-1236(527)
receiver1();
if(code1==1){
if(PORTB.F0==0){
receiver();
if(zer==1){
if(PORTB.F0==1){
receiver1();
if(code1==2){
if(PORTB.F0==0){
receiver();
if(zer==2){
if(PORTB.F0==1){
receiver0();
if(code==1){
if(PORTB.F0==0){
receiver();
if(zer==3){
if(PORTB.F0==1){
receiver1();
if(code1==3){
if(PORTB.F0==0){
receiver();
if(zer==4){
if(PORTB.F0==1){
receiver0();
if(code==2){
if(PORTB.F0==0){
receiver();
if(zer==5){
if(PORTB.F0==1){
receiver1();
if(code1==4){
if(PORTB.F0==0){
receiver();
if(zer==6){
if(PORTB.F0==1){
receiver0();
if(code==3){
if(PORTB.F0==0){
receiver();
if(zer==7){
if(PORTB.F0==1){
receiver1();
if(code1==5){
if(PORTB.F0==0){
receiver();
if(zer==8){
d1=175;
PORTB.F4=1;
PORTB.F1=1;
PORTB.F2=0;
PORTB.F5=0;
PWM1_change_duty(d1);
i22=250;
stop=100;
}}} } }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
if(stop==0){PORTB.F1=0;
PORTB.F2=0;
PORTB.F4=0;
PORTB.F5=0;}
code=0,code1=0,zer=0;
stop--;
i1=1,h1=1,i22=1,y1=1;
}
}
There is nothing wrong in the code.
I believe that statement is a bit premature.
The code above works without any problem(even with the presence of "void check();"), But when i add this "check();" in the main program , The PIC doesnt work !!!!
What I meant is there is nothing suspicious in check() function that would make PIC not to work.
I think these are causing the problem.
unsigned char y2[3],y3[3];
Change it to
unsigned char y2[17],y3[17];
--------------------------------------------------------------
void IntToStr(int input, char *output);
Returns Nothing.
Description Converts input signed integer number to a string. The output string has fixed width of 7 characters including null character at the end (string termination). The output string is right justified and the remaining positions on the left (if any) are filled with blanks.
Parameters :
input: signed integer number to be converted
output: destination string
Requires Destination string should be at least 7 characters in length.
Example int j = -4220;
char txt[7];
...
IntToStr(j, txt); // txt is " -4220" (one blank here)
-----------------------------------------------------------------------------------------
Code C - [expand] 1 2 3 4 5 6 7 unsigned char myStr[7]; unsigned int myInt = 0; //............ IntToStr(myInt, myStr); myStr[3] = '\0';
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 if(PORTB.F0==1){ //10010101-1236(527) receiver1(); if(code1==1){ if(PORTB.F0==0){ receiver(); if(zer==1){ if(PORTB.F0==1){ receiver0(); if(code==1){ if(PORTB.F0==0){ receiver(); if(zer==2){ if(PORTB.F0==1){ receiver0(); if(code==2){ if(PORTB.F0==0){ receiver(); if(zer==3){ if(PORTB.F0==1){ receiver1(); if(code1==2){ if(PORTB.F0==0){ receiver(); if(zer==4){ if(PORTB.F0==1){ receiver0(); if(code==3){ if(PORTB.F0==0){ receiver(); if(zer==5){ if(PORTB.F0==1){ receiver1(); if(code1==3){ if(PORTB.F0==0){ receiver(); if(zer==6){ if(PORTB.F0==1){ receiver0(); if(code==4){ if(PORTB.F0==0){ receiver(); if(zer==7){ if(PORTB.F0==1){ receiver1(); if(code1==4){ if(PORTB.F0==0){ receiver(); if(zer==8){ d1=255; d2=255; PORTB.F4=1; PORTB.F1=1; PORTB.F2=0; PORTB.F5=0; PWM1_change_duty(d1); PWM2_change_duty(d2); i1=250; stop=100; } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } }
BigDog... im using 434 MHz ASK module and it's similar to the picture, UART has a problem that will not make RF operate at a long distances.
AT the end of the program there's if statement (if stop==0), the "check();" is placed just before it.
The pic doesnt work means that the program is not occurred (it's not just for LCD), Just blocks are appeared.
jayanth... as i said the PIC works perfectly when i remove "check();" only. im declaring width of 3 characters only because i need to place two readings in one line, which cant be done when declaring 7 characters.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 if(PORTB.F0==1){ //10010101-1236(527) receiver1(); } if(code1==1){ if(PORTB.F0==0){ receiver(); } if(zer==1){ if(PORTB.F0==1){ receiver0(); } if(code==1){ if(PORTB.........
BigDog... u r right about the RF module, that what i have done in the transmitter code, where the "1" pulse consists of number of pulses (if "1" period is 1000us, i have to transmit a set of pulses of frequency ~38KHz for a duration of 1000us), that's also for the "0" pulse but with a little time period.
This is the programmer :
View attachment 93829
I will try to deal with sprintf()..
i now discover another problem, as u see in the code there are two PWMs i use, when i test the circuit, PORTB (LEDs) are having a little light, although PORTB state is "0".
i remove the declaraion of the second PWM and i found that the LEDs are not lightning when their state is"0".
sbit LCD_RS at RD4_bit;
sbit LCD_EN at RD5_bit;
sbit LCD_D4 at RD0_bit;
sbit LCD_D5 at RD1_bit;
sbit LCD_D6 at RD2_bit;
sbit LCD_D7 at RD3_bit;
sbit LCD_RS_Direction at TRISD4_bit;
sbit LCD_EN_Direction at TRISD5_bit;
sbit LCD_D4_Direction at TRISD0_bit;
sbit LCD_D5_Direction at TRISD1_bit;
sbit LCD_D6_Direction at TRISD2_bit;
sbit LCD_D7_Direction at TRISD3_bit;
I'm actually not sure if there are mikroProg clones available as I rarely use mikroE products, perhaps jayanth could shed some light on that subject.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?