Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] PIC18F4520 with MPLAB IDE v8.60 C Complier UART HELP!!!!

Status
Not open for further replies.

LuckyStar94

Newbie level 2
Newbie level 2
Joined
Jun 5, 2014
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
31
Hi everyone, I'm currently using a pic controller to communicate with a external device from atlas scientific (**broken link removed** ) However, I can't seem to establish a proper connection with it . I already made sure that I check the baud rate and the configuration setting but I can't seem to receive data from it. However, one thing I'm sure that it is receiving command from what I've written in my coding.
Here's my code so far:


Code C++ - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <p18f4520.h>
#include <usart.h>
#include <delays.h>
void Init_LCD(void);
void W_ctr_8bit(char);
void W_data_8bit(char);
 
#define LCD_DATA PORTD
#define LCD_RS PORTBbits.RB1
#define LCD_E PORTBbits.RB2
#define Rx PORTCbits.RC7
#define Tx PORTCbits.RC6
char MESS[41]={"Cal,Clear\r\n"};
char MESS1[]={"RESPONSE,1\r\n"};
char MESS2[]={"Welcome\r"};
 
void main(){
    char i,a;
    ADCON1=0x0f; // set port A B E as digital I/O
    TRISA=0b11111110;
    TRISB=0b11111001;
    TRISD=0b00000000;
    TRISC=0b10111111; //RC7 RX input  RC6 TX output
    SPBRG =32; // 20,000,000/[16(38400+1)]= Baud Rate 
    TXSTA=0b00100100; // asynchronous mode , 8-bit data
    RCSTA=0b10010000; // serial port enable, 8-bit data
 
for(i=0;i<40;i++)
{
    a = TXSTAbits.TRMT;
    while(!TXSTAbits.TRMT);
    TXREG=MESS[i];
}
 
Init_LCD();
W_ctr_8bit(0b10000100); //1st line  
for(i=0;i<40;i++)
{
    W_data_8bit(RCREG);
}
 
    
while(!TXSTAbits.TRMT);
    TXREG=0x0d;
    PORTAbits.RA0=1;
    Delay10KTCYx(50);
    PORTAbits.RA0=0;
    Delay10KTCYx(50);            
}
 
 
/*void interrupt SerialRXPinInterrupt()
{
    //check if the interrupt is caused by RX pin
    if(PIR1bits.RCIF == 1)
    {
    }
}*/ 
 
void Init_LCD(){
    W_ctr_8bit(0b00111000);
    W_ctr_8bit(0b00001100);
    W_ctr_8bit(0b00000110);
    W_ctr_8bit(0b00000001);
    W_ctr_8bit(0b00000010);
}
 
 
void W_ctr_8bit(char x){
    LCD_RS = 0;
    LCD_E =1;
    LCD_DATA =x;
    Delay10TCYx(50);
    LCD_E =0;
 
}
 
 
void W_data_8bit(char x){
    LCD_RS =1;
    LCD_E =1;
    LCD_DATA = x;
    Delay10TCYx(50);
    LCD_E =0;
 
}



Is it because I typed wrong in my coding? I'm still a amateur in coding so please pardon me. Hope you can guide me through thanks :D
 
Last edited by a moderator:

what is the crystal frequency?
how have you set up the oscillator? e.g.
Code:
#pragma config OSC = HS			// high speed scillator

initially try transmitting characters from the PIC to the PC - you will then see if anything is received (is transmission working at all?) or you receive garbage (baud rate problems).
once transmission is working you can move onto receiving data
 
Thanks Horace1 for replying. Yup I had a 20 MHz Crystal and I already set it in the configuration bits. I didn't try the pic to pc function as I don't have the necessary equipment ( such as Hyper Terminal , MAX232 , Serial port on my pc). From what I observed, I believed the pic is able to transmit properly as I can see the embedded circuit installed with the led is blinking representing data is receiving. Currently, I'm trying to read out from RCREG but it appear to be some weird japanese character display on the lcd.

On the side note : Can I use RC Oscillator for EUART? I read through some of the forum and saw that it's possible and I'm attempting right now but haven't made any progress yet.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top