View previous topic :: View next topic |
Author |
Message |
arisk4
Joined: 22 Sep 2016 Posts: 4
|
Picdem to Picdem receiving problem |
Posted: Thu Sep 22, 2016 3:52 am |
|
|
Hello I'm new in programming and I'm trying to make a simple transmit-receive program between two picdemos using the TXD and RXD. I checked with oscilloscope the transmit wire and it seems to send the data but in the receiver the LED doesn't blink.
The code for transmitter:
Code: |
#include <16F877A.h>
#use delay(CLOCK=4000000)
#use rs232(baud=9600,PARITY=N,XMIT=PIN_C6,RCV=PIN_C7)
#define LED_PIN PIN_B1
void main()
{
output_low(PIN_B1);
while(TRUE)
{
printf("hello");
delay_ms(1500);
output_toggle(PIN_B1);
delay_ms(100);
output_toggle(PIN_B1);
}
}
|
The code for receiver:
Code: |
#include <18F452.h>
#use delay(clock=9000000)
#use rs232(baud=9600,XMIT=PIN_C6,RCV=PIN_C7)
#define LCD_ENABLE_PIN PIN_D6
#define LCD_RS_PIN PIN_D4
#define LCD_RW_PIN PIN_D5
#define LCD_DATA4 PIN_D0
#define LCD_DATA5 PIN_D1
#define LCD_DATA6 PIN_D2
#define LCD_DATA7 PIN_D3
#include <lcd.c>
char read;
void main()
{
output_low(PIN_B1);
output_high(pin_d7);
lcd_init();
lcd_putc("\fHello\n");
while(TRUE)
{
if (khbit)
{
output_toggle(PIN_B1);
delay_ms(1000);
output_toggle(PIN_B1);
//getc(read);
//printf(lcd_putc, "Message:%c", read );
//lcd_putc(read);
}
}
}
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9271 Location: Greensville,Ontario
|
|
Posted: Thu Sep 22, 2016 5:26 am |
|
|
1st Q.
Do you really have a nine MHX xtal in the rcv PIC PCB ?
1st C.
Everytime you use the hardare UART,you need to add 'errors' to the USE RS232(...options...). This will clear the UART from an OE condition( 3 chars or more, rcvd but not serviced.
Jay |
|
|
arisk4
Joined: 22 Sep 2016 Posts: 4
|
|
Posted: Thu Sep 22, 2016 6:03 am |
|
|
1st. Yes i have a PICTail in the pcb with the all the pins. The pic is mounted on Picdem 2 plus board.
2nd. I added the error option but nothing changed. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19591
|
|
Posted: Thu Sep 22, 2016 7:05 am |
|
|
Quote: |
1st Q.
Do you really have a nine MHX xtal in the rcv PIC PCB ?
|
I'll repeat Temtronic's question.
The PICDem2 plus board has a 4MHz oscillator. Do you have a 9MHz one!. This is what you are telling the receiver code..... |
|
|
arisk4
Joined: 22 Sep 2016 Posts: 4
|
|
Posted: Thu Sep 22, 2016 7:14 am |
|
|
yes the receiving board has an 9MHz. The two board must be in the same frequency? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19591
|
|
Posted: Thu Sep 22, 2016 7:37 am |
|
|
No, but 9MHz, is a very 'odd' frequency. Normally only used for crystal filter units.
Before doing anything else, prove that this is really what you have:
Code: |
//for the receiver
#include <18F452.h>
#fuses NOWDT, HS
#use delay(clock=9000000)
void main(void)
{
output_low(PIN_B1);
while(TRUE)
{
delay_ms(1000);
output_toggle(PIN_B1);
}
}
|
Time the pulses on B1. Are they at 0.5Hz?. If not, your crystal is not 9Mhz (or is not actually a normal crystal - the filter units look like crystals, in some cases, but won't resonate properly). |
|
|
arisk4
Joined: 22 Sep 2016 Posts: 4
|
|
Posted: Thu Sep 22, 2016 9:56 am |
|
|
After all the oscillator wasn't 9MHz(they told me it was ) and i couldn't find the right frequency. I put another 4MHz oscillator and im receiving something now. Thanks for the help and quick answers!!!! |
|
|
|