Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Usart Receive bit doenst set

Status
Not open for further replies.

SneaKSz

Member
Hello all,

I am facing a stupid problem , I am able to send data to the pc and send data to the PIC.

The problem is that the pic doesnt set the receive bit.

Code:
void init(); 
void Strans(unsigned char W);

void InterruptHandlerHigh (void);

// High priority interrupt vector

#pragma code InterruptVectorHigh = 0x08 // comp mode default vector
void InterruptVectorHigh (void)
{
  _asm
    goto InterruptHandlerHigh //jump to interrupt routine
  _endasm
}

//----------------------------------------------------------------------------
// High priority interrupt routine

#pragma code
#pragma interrupt InterruptHandlerHigh

void InterruptHandlerHigh ()
{
	unsigned int i = RCREG;
		LATCbits.LATC1=1;
	if(PIR1bits.RCIF==1){

		if ( i==1){
	
		}
	
	}
}

void main(void){

init();// setup
	while(1){
	//	Strans(0x54);//T
	//	Strans(0x45);//E	
	//	Strans(0x53);//S	
	//	Strans(0x54);//T
		LATCbits.LATC1=1;
		if(PIR1bits.RCIF==1){
			unsigned int i = RCREG;
				LATCbits.LATC0=0;
		}
	
	}
} // end main	
void init(){
	ADCON0=0x0;//Configure A/D
	TRISCbits.TRISC0=0;
	TRISCbits.TRISC1=0;
	LATCbits.LATC0=1;
	LATCbits.LATC1=0;
// Serial communication

	TXSTA=0x20;// enable transmit 
	SPBRG=19; // 9600 bps
	TRISBbits.TRISB7=0;//TX out
	TRISBbits.TRISB5=1; //RX
	RCSTA=0x90;//enable receive + serial port.
	TXSTAbits.TXEN=1;
	PIE1bits.RCIE=1;
	INTCONbits.GIE=1;
	INTCONbits.PEIE=1;

}

void Strans(unsigned char W){
while(PIR1bits.TXIF==0); // wait until the last bit is gone
TXREG=W;

}


This is a typical usart TX RC code .

I see the data on the Rx pin , but the interrupt flag doesnt set.

Thanks in advance!
 
I think that you need to clear the RCIF flag when data has arrived.

You could try without interrupts, just polling the RCIF flag. When it is set, clear it and toggle an output pin.
 
Hi Diver ,
I am using interrupts AND polling , when the RCIF is set , I read the register :
unsigned int i = RCREG;

Its a weird problem !
 
The RCIF interrupt flag is set and cleared by the hardware. Once RCREG is full, the flag sets. The flag clears upon moving the data from RCREG into the W register.

One thing most people forget with the USART is that the RX/TX pins are BOTH supposed to be configured as "analog input" in their applicable TRIS register. Then, once bit SPEN in RCSTA is set, this tells the hardware that the RX/TX pins are assigned to the USART IF the TRIS control bits for those pins are both set.
 
Last edited:
hye brothers
seriously i need a help with my project
i want to make temprature sensor with lcd 16x2 by using pic16f877a and the reading send over max232 through serial port and take the reading from the pc
so plzz brother if anyone can help me
with the code in mikroC
and the whole circuit and the programe that i can use to get the received reading
i do circuit that i was able through it to write onto the lcd through pc but i am not able now to display on pc what the temp sensor reading

iam thankful
 
this is my codee :
/ LCD Pinout settings
sbit Lcd_RS at RB0_bit;
sbit lcd_En at RB1_bit;
sbit lcd_D4 at RB2_bit;
sbit lcd_D5 at RB3_bit;
sbit lcd_D6 at RB4_bit;
sbit lcd_D7 at RB5_bit;
// Pin direction
sbit lcd_RS_Direction at trisb0_bit;
sbit lcd_En_Direction at trisb1_bit;
sbit lcd_D4_Direction at trisb2_bit;
sbit lcd_D5_Direction at trisb3_bit;
sbit lcd_D6_Direction at trisb4_bit;
sbit lcd_D7_Direction at trisb5_bit;
int temp1;
char temp[10];
void adc(){
temp1=ADC_READ(0);
temp1=temp1*0.245*2;
INTToStr(temp1,temp);}
void main() {
TRISA = 0xFF;
TRISD=0;PORTD=0;
TRISB=0;PORTB=0;
TRISc=1;PORTc=0;
Uart1_init(9600);
Lcd_Init();
lcd_cmd(_LCD_CURSOR_OFF);
while (1) {
lcd_out(1,10,temp);
UART1_Write_Text("temperature");
UART1_Write_Text(temp);UART1_Write(13);UART1_Write(10);;Delay_ms(1000);;
adc();
} }
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top