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.

[Help] Receiving data from PC - EUSART

Status
Not open for further replies.

VoltVolt

Junior Member level 1
Joined
Sep 15, 2013
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
124
Hi everyone,
I couldn't find out what's wrong with my codes.
What I want to do is just let my PIC receiving a character 'A' from VB6.0 software and set high on all the output ports...
So basically the char 'A' is to trigger the ports to turn on...
I'm not sure whether i write like that:
"RCREG1 == 'A'"
since RCREG is a 8-bit register, and it's function is to store receive data?
Compiler: MPLABX IDE
microcontroller: PIC18F45K22


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
#include <htc.h>
 
/* Start of configuration fuses*/
#pragma config IESO=OFF, FOSC=INTIO67,PRICLKEN=OFF,FCMEN =OFF,PLLCFG=ON,BOREN=ON,BORV=250
#pragma config WDTEN=OFF
#pragma config P2BMX=PORTC0,CCP2MX=PORTC1,PBADEN=OFF,CCP3MX=PORTE0,MCLRE=INTMCLR,HFOFST=OFF,T3CMX=PORTC0
#pragma config DEBUG=OFF,STVREN=ON,XINST=OFF,LVP=OFF
#pragma config CP0=OFF,CP1=OFF,CP2=OFF,CP3=OFF
#pragma config CPB=OFF,CPD=OFF
#pragma config WRT0=ON,WRT1=ON,WRT2=ON,WRT3=ON
#pragma config WRTB=ON,WRTC=ON,WRTD=ON
 
/* end of configuration fuses */
initReceive() {
    OSCCON = 0b11110011; //16MHz internal oscillator
 
    //    Synchronous Master Reception Setup:
    // 1. Initialize the SPBRGHx, SPBRGx register pair for the appropriate
    //baud rate. Set or clear the BRGH and BRG16 bits, as required,
    //to achieve the desired baud rate.
    SPBRGH1 = 0X01;
    SPBRG1 = 0XA0;
    TXSTA1bits.BRGH = 1;
    BAUDCON1bits.BRG16 = 1;
 
    // 2. Set the RXx/DTx and TXx/CKx TRIS controls to ‘1’.
    TRISC = 0b11000000; //set TX1 and RX1 as input
 
    // 3. Enable the synchronous master serial port by setting bits SYNC,
    //SPEN and CSRC. Disable RXx / DTx and TXx / CKx output drivers
    //by setting the corresponding TRIS bits.
    ANSELB = 0; //disable Analog Select
    SYNC1 = 0; //asynchronous mode
    SPEN1 = 1; //enable EUSART
    CSRC1 = 1;
 
    // 4. If interrupts are desired, set the RCxIE interrupt enable
    //bit and set the GIE/GIEH and PEIE/GIEL bits of the INTCON register.
    // 5. If 9-bit reception is desired, set the RX9 bit.
    // 6. Set the DTRXP if inverted receive polarity is desired.
    //enable data to be transmited
    // 7. Enable reception by setting the CREN bit.
    CREN1 = 1;
 
    // 8. The RCxIF interrupt flag bit will be set when a character
    //is transferred from the RSR to the receive buffer. An interrupt
    //will be generated if the RCxIE interrupt enable bit was also set.
 
    // 9. Read the RCSTAx register to get the error flags and,
    //if 9-bit data reception is enabled, the ninth data bit.
 
    // 10. Get the received eight Least Significant data bits from
    //the receive buffer by reading the RCREGx register.
    //will be execute at main function
 
    // 11. If an overrun occurred, clear the OERR flag by clearing
    //the CREN receiver enable bit.
}
 
void main() {
    initReceive();
    while (1) {
        if (RCREG1 == 'A') {
            TRISA = 0;
            LATA = 0xFF;
        }
    }
}



Thanks.....
 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top