Johnny Churne
Member level 5
some time i startup my pic 16f876a it work without follow the instruction! I used serial port to send data to it and some time it repeat about 3 times. please help my knowledge is limited.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
char receive[64] ;
void main(){
int x;
int i=0;
TRISA=0X00;
TRISB=0XFF;
TRISC=0X80;
PORTC=0X00;
PORTA=0X00;
PORTB=0X00;
UART1_INIT(9600);
delay_ms(100);
while(1){
if(Uart1_data_ready()==1){
uart1_read_text(receive,'F',65);
for(i=0;i<64;i++){
switch(receive[i]){
case'1': x=1; break;
case'0': x=0; break;
}
PORTA=x;
delay_ms(50);
PORTA=0X00;
delay_ms(50);
}
uart1_write('F');
} // end if
} // end while
}// end main
Means exactly what?it work without follow the instruction
I wanted to send string code such as binary code to pic and pic will execute if it receive 1 in each block array. I am doing this in purpose to hake CNC 2 axis the binary 1 is the coordinate write.
Please give me more advise!
unsigned short q=0;
void interrupt()
{
if(PIR1.RCIF==1)
{
receive[q]=UART1_Read();//copy byte by byte in receive
q++;
}
}
char receive[64] ;
void main(){
int x;
int i=0;
TRISA=0X00;
TRISB=0XFF;
TRISC=0X80;
PORTC=0X00;
PORTA=0X00;
PORTB=0X00;
UART1_INIT(9600);
RCIE_bit=1;
INTCON.GIE=1;
PIE1_bit=1;
delay_ms(100);
while(1){
if(q>64)q=0;
if(receive[0]=='0')
{
x=0;
q=0;//resetting q to 0
}
if(receive[1]=='1')
{
x=1;
q=0;
}
PORTA=x;
delay_ms(50);
PORTA=0X00;
delay_ms(50);
}
uart1_write('F');
} // end if
} // end while
I agree with your suggestion to use UART interrupts. But I actually wanted to ask the OP for an example of the CNC input data.
Zip and post the complete mikroC project file. I have to see the project settings.
Address Value Field Category Setting
2007 2F4A FOSC Oscillator Selection bits HS oscillator
WDTE Watchdog Timer Enable bit WDT disabled
PWRTE Power-up Timer Enable bit PWRT disabled
BOREN Brown-out Reset Enable bit BOR enabled
LVP Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit RB3 is digital I/O, HV on MCLR must be used for programming
CPD Data EEPROM Memory Code Protection bit Data EEPROM code protection off
WRT Flash Program Memory Write Enable bits Write protection off; all program memory may be written to by EECON control
CP Flash Program Memory Code Protection bit Code protection off
I used MikroC
- - - Updated - - -
it can not compile in PIE1_bit=1;
what's the problem?
Mrunal Ahirrao
I really don't understand, my setting is the same as shown but it still doesn't work.The configuration shows WDT disabled. So everything is inside the shown code.
Code:Address Value Field Category Setting 2007 2F4A FOSC Oscillator Selection bits HS oscillator WDTE Watchdog Timer Enable bit WDT disabled PWRTE Power-up Timer Enable bit PWRT disabled BOREN Brown-out Reset Enable bit BOR enabled LVP Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit RB3 is digital I/O, HV on MCLR must be used for programming CPD Data EEPROM Memory Code Protection bit Data EEPROM code protection off WRT Flash Program Memory Write Enable bits Write protection off; all program memory may be written to by EECON control CP Flash Program Memory Code Protection bit Code protection off