BoostC USART 18F

Status
Not open for further replies.

AtomSoft

Well-Known Member
Ok im having some trouble receiving from Hyper Terminal to my PIC18F1320.
Im using BoostC to program/

I can send data out with no problem... Here is my receive code:
Code:
void RxRecv(char &MyTmp)
{
    while(!pir1.RCIF);

        MyTmp = rcreg;
        Rs_Send(rcreg);
}
and this is how im calling it
Code:
    while(1)
    {
        char Tmp2 = 0x00;
        RxRecv(Tmp2);
    }
Now for some reason when i type a key in hyper terminal it wont work. But i have the same code in ASM and it works fine on same chip. Any thoughts?
 
Last edited:
The argument of the function RxRecv() looks wrong to me.
Does this work?

Code:
unsigned char MyTmp;

unsigned char RxRecv(){

    while(!PIR1.RCIF);
    return RCREG;

}

// ....

while(1){

    MyTmp = RxRecv();
    Rs_Send(MyTmp);

}
 
Last edited:
I can send data out with no problem... Here is my receive code:
Code:
void RxRecv(char &MyTmp)
{
    while(!pir1.RCIF);

        MyTmp = rcreg;
        Rs_Send(rcreg);
}

Try changing it to void RxRecv(char *MyTmp) and your calling code to RxRecv(&Tmp2);

The (char *) tells the compiler to expect a pointer with the address of a char variable and &Tmp2 passes the address of the variable.

Mike.
 
Last edited:
The actual issue is i cant seem to get passed the (bold):
Code:
void RxRecv(char *MyTmp)
{
    while(!pir1.RCIF);  //Not correctly checking Flag even with 
                        //a breakpoint i cant skip this

        *MyTmp = rcreg;
        Rs_Send(rcreg);
}
 
yes here is my full code: (still nothing)
Code:
#include <p1320.h>
#pragma	CLOCK_FREQ 8000000

void Rs_Init()
{
    //RS Init.
    trisb = 0b00010010;
    portb = 0x00;
    spbrg = 0x0C;
    txsta.BRGH = 0;
    baudctl.BRG16 = 0;
    txsta.SYNC = 0;
    rcsta.SPEN = 1;
    rcsta.CREN = 1;
    txsta.TXEN = 1;
}

void Rs_Send (char tx_char)
{
    while(!pir1.TXIF);
    txreg = tx_char;
        
}

void puts(char *source)
{
	while (*source != 0) // wait until tx register is empty
	    Rs_Send(*source++);
        Rs_Send(0x0d);
        Rs_Send(0x0a);
}


void RxRecv(char *MyTmp)
{
    while(!pir1.RCIF);  //Not correctly checking Flag even with 
                        //a breakpoint i cant skip this

        *MyTmp = rcreg;
        Rs_Send(rcreg);
}


void main()
{
    //PIC Init.
    osccon.IRCF2 = 1; // 8Mhz Clock
    osccon.IRCF1 = 1;
    osccon.IRCF0 = 1;

    Rs_Init();    

    puts("Hello, world\r\n");
  
    while(1)
    {
        char Tmp2 = 0x00;
        RxRecv(&Tmp2);
    }
}
 
Last edited:
You did not configured the A/D channels, did you? Try adding this line at the begining of the main function:
Code:
ADCON1 = 0xFF;
 
Does this work?
Code:
char Tmp2 = 0x00;
while (1) {
      if (pir1.RCIF) {
         Tmp2 = rcreg;
         Rs_Send(Tmp2);
      } // end if
} // end while

Why not use an interrupt?
 
Last edited:
You did not configured the A/D channels, did you? Try adding this line at the begining of the main function:
Code:
ADCON1 = 0xFF;

Thanks a bunch! this works now. I should have seen it in my asm code but i guess i was going to fast! thanks a lot.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…