hello ediamondsrt,
Code:
TXSTA = 0x24; -----> are you using synchronous mode ???
SYNC = 0;
SPEN = 1;
TXEN = 1;
BRGH = 1;
SPBRG = 129;
***** you have to enable Peripheral Interrupt Enable bit****
Code:
SREN = 0;
RCIE = 1; // Interrupt Enable
CREN = 1;
GIE = 1;
i had enclosed interrupt driven UART receiver code .... it may help you
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
| //_______________________________________________________________
// UART_RX_CODE_16f628a
//________________________________________________________________
#include <pic.h>
//___________________________________________________
// PORT INIT
//___________________________________________________
#define init_ports() PORTA=0x00,TRISA=0x00,\
PORTB=0x00,TRISB=0x02;
//___________________________________________________
// UART INIT
//___________________________________________________
#define init_uart() SPBRG=0x67,TXEN=0,TXSTA=0x04,\
RCSTA=0x90,INTCON=0x40,PIE1=0x20;
//BRGH = 1
//SPEN = 1,CREN = 1,
//RCIE = 1,PEIE = 1 -- Peripheral Interrupt Enable bit
//___________________________________________________
// GENERAL INIT
//___________________________________________________
bit Data_Rce_Flag,Err_FERR_flag=0,Err_OERR_flag=0;
unsigned char Res_Buff[10],cnt,Err_Buff,Data_Cnt;
#define PORTBIT(adr, bit) ((unsigned)(&adr)*8+(bit))
static bit Ten_Data_Rec_Ind @ PORTBIT(PORTB, 5);// Pin RB5 will indicate successful data reseve
//___________________________________________________
// Intrrupt Routine
//___________________________________________________
static void interrupt isr(void)
{
if(RCIF)
{
RCIF=0;
if(FERR)
{
Err_Buff=RCREG;
Err_FERR_flag=1;
}
else if(OERR)
{
CREN=0;
CREN=1;
Err_OERR_flag=1;
}
if(!(Err_FERR_flag & Err_OERR_flag))
{
Res_Buff[Data_Cnt]=RCREG;
Data_Cnt++;
if(Data_Cnt > 0x0A)
Data_Rce_Flag = 1;
}
Err_FERR_flag=0;
Err_OERR_flag=0;
}
}
///________________________________________________________
// DELAY
//_________________________________________________________
void delay(unsigned char cnt)
{
unsigned long int count=cnt;
count=count*2;
while(count--);
}
//_________________________________________________________
// MAIN
//_________________________________________________________
void main()
{
init_ports();
init_uart();
GIE=0;
delay(10);
GIE=1;
while(1)
{
if(Data_Rce_Flag)
{
Data_Rce_Flag=0;
Ten_Data_Rec_Ind = 1;
}
}
} |
regards
amar