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.

Compile Code for USART PIC18F45K22

Status
Not open for further replies.
Advanced Member level 6
Joined
Dec 4, 2012
Messages
4,280
Helped
822
Reputation
1,654
Reaction score
791
Trophy points
1,393
Location
Bangalore, India
Visit site
Activity points
0
I have written a USART program for PIC18F45K22 in MPLAB 8.89 with Hi-Tech C PICC-18 9.90 as the Compiler but when I try to build the project nothing happens. The ouput files are not created. My other Hi-Tech projects Compile fine but this project is not Compiling. Can someone please build the project (Release and Debug versions) and send me the hex file. My Fosc is 16 MHz

I have attached the project files. I am using Hi-Tech C PICC-18 9.80 PRO. Can somebody guess what might be the problem for project not Compiling?

I have modified the code. Here is my new code. It is not working. I am just trying to transmit a character 'A' to USART.


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
#include <htc.h>
 
//__CONFIG(FOSC_HS & WDTE_OFF & PWRTE_ON & CP_OFF & BOREN_ON & LVP_OFF & CPD_OFF & WRT_ON & DEBUG_OFF);
 
#define _XTAL_FREQ 16000000   //MHz
 
 
int main() 
{
    
    TRISDbits.RD6 = 0;      //TX Pin
    TRISDbits.RD7 = 1;      //Rx Pin
    
    PORTD = 0x00;
    
        
    INTCONbits.PEIE = 1;
    INTCONbits.GIEL = 1;
    INTCONbits.GIE = 1;
    INTCONbits.GIEH = 1;
    PIE1bits.RC1IE = 1;
    PIE1bits.TX1IE = 1;
    PIE3bits.RC2IE = 1;
    PIE3bits.TX2IE = 1;
    IPR1bits.TX1IP = 0;
    
    BAUDCON1bits.BRG16 = 0;
    BAUDCON2bits.BRG16 = 0;
    
    
    SPBRG2 = 25;
    
    TXSTA2 = 0x2A;
    RCSTA2bits.SPEN = 1;
    
    ANSELD = 0xFF;
    
    /*
    TXSTA1bits.TX9D = 0;
    TXSTA1bits.TRMT = 1;
    TXSTA1bits.BRGH = 1;
    TXSTA1bits.SENDB = 0;
    TXSTA1bits.SYNC = 0;
    TXSTA1bits.TXEN = 1;
    TXSTA1bits.TX9 = 0;
    TXSTA1bits.CSRC = 0;
    */
    
    
    while(1)
    {
            TXREG2 = 'A';
            while(PIR3bits.TX2IF == 0);
            
            
    }
}

 

Attachments

  • uart.rar
    23.6 KB · Views: 85
Last edited:

Here is my new code and it is still not working. In Proteus I get some "stack overflow is forcing device reset" error.

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
#include <htc.h>
 
//__CONFIG(FOSC_HS & WDTE_OFF & PWRTE_ON & CP_OFF & BOREN_ON & LVP_OFF & CPD_OFF & WRT_ON & DEBUG_OFF);
 
#define _XTAL_FREQ 16000000   //MHz
 
void main() {
    
    TRISC = 0x80;
 
    INTCONbits.GIE = 1;
    INTCONbits.GIEH = 1;
    INTCONbits.PEIE = 1;
    INTCONbits.GIEL = 1;
    PIE1bits.RC1IE = 1;
    PIE1bits.TX1IE = 1;
    PIE3bits.RC2IE = 1;
    PIE3bits.TX2IE = 1;
    IPR1bits.RC1IP = 0;
    IPR1bits.TX1IP = 1;
    IPR3bits.RC2IP = 0;
    IPR3bits.TX2IP = 1;
    PIR4bits.CCP3IF = 0;
    PIR1bits.TX1IF = 1;
    
    ANSELC = 0x00;
 
    TXSTA1bits.TX9 = 0;
    TXSTA1bits.TXEN = 1;
    TXSTA1bits.SYNC = 0;
    TXSTA1bits.BRGH = 1;
    TXSTA1bits.TRMT = 1;
    RCSTA1bits.SPEN = 1;
    SPBRG = 25;
    BAUDCON1bits.BRG16 = 0;
 
    while(1)
    {
        TXREG1='A';
        while(PIR1bits.TX1IF == 0);
                
    }
    
    
}

 

Add pullup resistor (20K) at MCLR pin in scheme (for PROTEUS).:wink:
 

#include <htc.h>
#include <p18f45k22.h>
//#pragma __CONFIG(FOSC_HS & WDTE_OFF & MCLR_ON & PWRTE_ON & CP_OFF & BOREN_ON & LVP_OFF & CPD_OFF & WRT_ON & DEBUG_OFF);
#define _XTAL_FREQ 16000000 //MHz
void main() {

TRISB = 0;
PORTBbits.RB0 = 1;

// ANSELC = 0x00;

TXSTA1bits.TX9 = 0;
TXSTA1bits.TXEN = 1;
TXSTA1bits.SYNC = 0;
TXSTA1bits.BRGH = 0;
TXSTA1bits.TRMT = 1;
RCSTA1bits.SPEN = 1;

SPBRG = 12;
// SPBRGH = 0;
BAUDCON1bits.BRG16 = 0;

while(1)
{
TXREG1='A';
// while(PIR1bits.TX1IF == 0);

}
}

I have done that and it is not working.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top