LuckyStar94
Newbie level 2
- Joined
- Jun 5, 2014
- Messages
- 2
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- 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:
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
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
Last edited by a moderator: