Page 3 of 4

Posted: 21 Aug 2009 20:06
by Tanky321
Thank you very much, I really appreciate all of your help!!

Posted: 26 Aug 2009 22:46
by Tanky321
I've been messing around with this some more, and havent gotten any where. the only thing i can think is that my device flags are not set right.


What I have set is:


WDT_OFF

MCLRE_OFF

INTOSC_OSC_NOCLKOUT


Im not sure if Im missing anything, or if I shouldnt have one of these checked off.


Thanks

Posted: 27 Aug 2009 06:07
by drdoug
I found a 648A to play with and I'll try to squeeze it in tomorrow.

Posted: 27 Aug 2009 15:16
by drdoug
I hate microcontrollers!
Here is what I seem to find after I finally programmed the chip in the correct port (DIP 18B).

It seems like the RCREG port is not being cleared and so USART_Data_Ready is always testing true and so it always enters that loop and assigns "i" the variable that is in that register.

The code will work but you have to send another character to clear out the RCREG. I will also try to port the code to Pro C and see what happens.

Code: Select all

unsigned char i;
unsigned char rxnum;

void main() {
//INTCON.GIE = 0;                   // Disable interrupts

CMCON = 7;                        //Declare Variables
VRCON = 0;
PORTA = 0;  //Init. PORTA
PORTB = 0;                        //& PORTB
TRISA = 0x00;
TRISB = 0x00;
//TRISB.F1 = 1;
//rxnum = 0;

Usart_Init(2400);                  //Establish USART at 2400bps

PORTB.F5 = 1;
Delay_ms(1000);
PORTB.F5 = 0;
Delay_ms(1000);

while(1){

  if(Usart_Data_Ready){

    i = Usart_Read();
 //   i = RCREG;
  //  Usart_Write(i);  // write data back to computer

  }

 if( i == 65){
  PORTB.F4 = 1;     // Flash light if "A" is received
  Delay_ms(1000);
  PORTB.F4 = 0;
  Usart_Write(i);
  i = 0;
  
     }
     
  if( i == 66){
  PORTB.F5 = 1;     // Flash light if "A" is received
  Delay_ms(1000);
  PORTB.F5 = 0;
  Usart_Write(i);
  i = 0;
     }
} // end while
} // end main

Posted: 27 Aug 2009 15:24
by Mince-n-Tatties
drdoug wrote:I hate microcontrollers!
don't be hatin :wink:

Posted: 27 Aug 2009 15:25
by drdoug
I just ported the code over to Pro C and had the same problem so I think it may be a compiler issue. I do not have time to look through the ams now but it may be worth starting a trouble ticket (or I am just missing something obvious which I have already done several times this AM).

Posted: 27 Aug 2009 18:25
by Tanky321
This did in fact end up working, im going to try and see if I can figure anything out with my actual code. Il post the results.



Thanks again!

Posted: 28 Aug 2009 16:56
by Tanky321
This is killing me, I cant get anywhere. Ive hooked the receiver to the Terminal and I get no response what so ever. I send the values separately and together and I get no response. I figured I would clear the RCREG at the end of the loop, but im just kinda shooting from the hip. Any other insight into this pain in the butt?

Thanks!

Code: Select all

unsigned short i, rxdata[3];

unsigned int rxnum;



void main() {
INTCON.GIE = 0;                   // Disable interrupts

cmcon = 7;                        //Declare Variables
VRCON = 0;
TRISA = 0;                    //Set PORTA as output
TRISB = 0;                    //Set PORTB as output
TRISB.F1 = 1;                    //Set PORTB bit 1 as input
PORTA = 0xFF;                     //Init. PORTA
PORTB = 0;
PORTB.F4 = 1;
PORTB.F5 = 1;                      //& PORTB




Usart_Init(2400);                  //Establish USART at 2400bps


while(1){

 if(Usart_Data_Ready()){

     i = Usart_Read();
  }

 if( i == 65){
  rxnum = 0;
  while( rxnum < 3){
          if(Usart_Data_Ready()){
               rxdata[rxnum] = Usart_Read();
               rxnum++;
     }
   if((rxdata[1] == 66) && (rxdata[2] == 35)){

     PORTA = rxdata[0];}
      //Delay_ms(1000); // Longer delay so you dont miss anything
 }}


 if ( rxdata[0] == 239) {
      PORTB.F4 = 0;
     //Delay_ms(1000); // Longer delay so you dont miss anything
     //PORTA = 0XFF;
     //PORTB.F4 = 1;
     }

   if ( rxdata[0] == 223) {
      PORTB.F5 = 0;
     //Delay_ms(1000);
     //PORTA = 0XFF; // Longer delay so you dont miss anything
     //PORTB.F5 = 1;
     }
Delay_ms(1000);
PORTA = 0XFF; // Longer delay so you dont miss anything
PORTB.F5 = PORTB.F4 = 1;

RCREG = 0;


}
}

Posted: 30 Aug 2009 20:33
by drdoug
It looks like you have a 1 second delay after you 1 byte of the uart which wouldkeep you from receiving any other characters.

I'll try to play with your code again later.

Posted: 03 Sep 2009 14:25
by nikola.kostic
Tanky321,

Try adding Delay_ms(100); after Usart_Init(2400);.

Code: Select all

...
Usart_Init(2400);                  //Establish USART at 2400bps
Delay_ms(100);
...

Posted: 07 Sep 2009 16:19
by Tanky321
Thanks for the replies! Il be trying this soon, I ended up installing Ubuntu on my desktop forgetting that I needed it for the UART terminal! I ended up ordering a USB to RS232 connector, so I will let you guys know how I make out soon.

Posted: 16 Sep 2009 02:18
by Tanky321
drdoug wrote:It looks like you have a 1 second delay after you 1 byte of the uart which wouldkeep you from receiving any other characters.

I'll try to play with your code again later.
Im a little confused as to what your saying? Im not sure which delay your talking about.

I ended up getting my USB to RS232 converter and I tried the 100mS delay, but it didnt help either.

Thanks

Posted: 21 Sep 2009 13:15
by Tanky321
Anyone?

Posted: 21 Sep 2009 14:02
by drdoug
Consider this modification

Code: Select all

...
   if ( rxdata[0] == 223) {
      PORTB.F5 = 0;
     //Delay_ms(1000);
     //PORTA = 0XFF; // Longer delay so you dont miss anything
     //PORTB.F5 = 1;
     }
// Delay_ms(1000); // you'll miss a lot of data if you wait 1 second here
PORTA = 0XFF; // Longer delay so you dont miss anything
PORTB.F5 = PORTB.F4 = 1;

 RCREG = 0;  


}
}
What happened when you tried the code I sent?

Posted: 21 Sep 2009 21:39
by Tanky321
Im not sure which code you mean? Did you send an email or PM or something?


Thanks