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.

Peripheral Pin Select Module of PIC18F27J53 not working???

Status
Not open for further replies.

xpress_embedo

Advanced Member level 4
Joined
Jul 5, 2011
Messages
1,154
Helped
161
Reputation
396
Reaction score
189
Trophy points
1,353
Location
India
Activity points
10,591
Hello!! i am using PPS in-built in PIC18F2753, to operate UART-2 Communication, but it is not doing any thing.
Is there some thing wrong with my code.


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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <p18F27J53.h>
#include <delays.h>
 
/******************CONFIGURATION BITS****************/
#pragma config WDTEN = OFF          //WDT disabled (enabled by SWDTEN bit)
#pragma config PLLDIV = 5           //Divide by 5 (20 MHz oscillator input)
#pragma config STVREN = ON          //stack overflow/underflow reset enabled
#pragma config XINST = OFF          //Extended instruction set disabled
#pragma config CPUDIV = OSC1        //No CPU system clock divide
#pragma config CP0 = OFF            //Program memory is not code-protected
#pragma config OSC = HSPLL          //HS oscillator, PLL enabled, HSPLL used by USB
#pragma config FCMEN = OFF          //Fail-Safe Clock Monitor disabled
#pragma config IESO = OFF           //Two-Speed Start-up disabled
#pragma config WDTPS = 32768        //1:32768
#pragma config DSWDTOSC = INTOSCREF //DSWDT uses INTOSC/INTRC as clock
#pragma config RTCOSC = T1OSCREF    //RTCC uses T1OSC/T1CKI as clock
#pragma config DSBOREN = OFF        //Zero-Power BOR disabled in Deep Sleep
#pragma config DSWDTEN = OFF        //Disabled
#pragma config DSWDTPS = 8192       //1:8,192 (8.5 seconds)
#pragma config IOL1WAY = OFF        //IOLOCK bit can be set and cleared
#pragma config MSSP7B_EN = MSK7     //7 Bit address masking
#pragma config WPFP = PAGE_1        //Write Protect Program Flash Page 0
#pragma config WPEND = PAGE_0       //Start protection at page 0
#pragma config WPCFG = OFF          //Write/Erase last page protect Disabled
#pragma config WPDIS = OFF          //WPFP[5:0], WPEND, and WPCFG bits ignored
#pragma config CFGPLLEN = OFF
/****************************************************/
 
#define RAM_SIZE 16
 
/******************FUNCTION PROTOTYPE*******************/
void Delay_ms(unsigned int itime);
void UART1_Init(void);
void UART1_Write(unsigned char value);
void UART1_Write_Text(unsigned char msg[]);
void UART2_Init(void);
void UART2_Write(unsigned char value);
void UART2_Write_Text(unsigned char msg[]);
void Clear_Ram_Buffer(unsigned char ram_msg[]);
unsigned char * ConstToRAM(unsigned char * dest, const rom unsigned char * src);
/*******************************************************/
 
const rom unsigned char text[] = "EDA BOARD";
 
void main()
{
    unsigned char ram_data[RAM_SIZE];
    INTCONbits.GIE = 0;
    EECON2 = 0x55;
    EECON2 = 0xAA;
    PPSCONbits.IOLOCK = 0;
    
    RPINR16 = 0x00;
    RPOR1 = 0x06;
    
    INTCONbits.GIE = 0;
    EECON2 = 0x55;
    EECON2 = 0xAA;
    PPSCONbits.IOLOCK = 1;
    
    TRISAbits.TRISA0 = 1;
    TRISAbits.TRISA1 = 0;
    
    UART1_Init();
    UART2_Init();
    ConstToRAM(ram_data,text);
    UART1_Write_Text(ram_data);
    UART2_Write_Text(ram_data);
    while(1);
}
 
/******************FUNCTION PROTOTYPE*******************/
void Delay_ms(unsigned int itime)
{
    unsigned int first;
    unsigned int second;
    for(first=0;first<itime;first++)
    {
        for(second=0;second<650;second++)
        {
            Delay1TCY();
        }
    }
}
void UART1_Init(void)
{
    TRISCbits.TRISC7 = 1;
    TRISCbits.TRISC6 = 0;
    TXSTA1 = 0b00100010;
    BAUDCON1bits.BRG16 = 0;
    SPBRG1 = 77;
    RCSTA1 = 0b10010000;
}
void UART1_Write(unsigned char value)
{
    while(PIR1bits.TX1IF == 0); //Wait Until Flag Gets Set
    TXREG1 = value;
}
void UART1_Write_Text(unsigned char msg[])
{
    while(*msg)
    {
        UART1_Write(*msg);
        msg++;
    }
}
void UART2_Init(void)
{
    TXSTA2 = 0b00100010;
    BAUDCON2bits.BRG16 = 0;
    SPBRG2 = 77;
    RCSTA2 = 0b10010000;
}
void UART2_Write(unsigned char value)
{
    while(PIR3bits.TX2IF == 0); //Wait Until Flag Gets Set
    TXREG2 = value;
}
void UART2_Write_Text(unsigned char msg[])
{
    while(*msg)
    {
        UART2_Write(*msg);
        msg++;
    }
}
void Clear_Ram_Buffer(unsigned char ram_msg[])
{
    unsigned char i;
    for(i=0;i<RAM_SIZE;i++)
    {
        ram_msg[i] = 0;
    }
}
unsigned char * ConstToRAM(unsigned char * dest, const rom unsigned char * src)
{
    for(;*dest++ = *src++;)
    ;
    return dest;
}
/*******************************************************/



UART1 is working but not the second one
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top