1248 |
mija |
1 |
#include "C:\projekts\PIC_SW\PIC16F88\RS232\rs232.h" |
|
|
2 |
|
|
|
3 |
#define RCSTA *0x18 |
|
|
4 |
#define CREN 4 |
|
|
5 |
#define OERR 1 |
|
|
6 |
#define FERR 2 |
|
|
7 |
|
|
|
8 |
#define _BV(a) (1<<(a)) |
|
|
9 |
|
|
|
10 |
#int_RDA |
|
|
11 |
RDA_isr() |
|
|
12 |
{ |
|
|
13 |
putc(getc()); |
|
|
14 |
} |
|
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
char bit_1,bit_2,bit_3,bit_4; |
|
|
19 |
unsigned int time; |
|
|
20 |
|
|
|
21 |
void main() { |
|
|
22 |
|
|
|
23 |
//char a,b,c; |
|
|
24 |
|
|
|
25 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
|
|
26 |
setup_adc(ADC_OFF); |
|
|
27 |
setup_spi(FALSE); |
|
|
28 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
|
|
29 |
setup_timer_1(T1_DISABLED); |
|
|
30 |
setup_timer_2(T2_DISABLED,0,1); |
|
|
31 |
setup_comparator(NC_NC_NC_NC); |
|
|
32 |
setup_vref(FALSE); |
|
|
33 |
//enable_interrupts(INT_RDA); |
|
|
34 |
//enable_interrupts(GLOBAL); |
|
|
35 |
setup_oscillator(OSC_4MHZ); |
|
|
36 |
|
|
|
37 |
input(PIN_B2); |
|
|
38 |
|
|
|
39 |
printf("\ftest rs232\n\r"); |
|
|
40 |
|
|
|
41 |
time = 0; |
|
|
42 |
for(;;) |
|
|
43 |
{ |
|
|
44 |
bit_1 = getc(); |
|
|
45 |
delay_ms(time); |
|
|
46 |
|
|
|
47 |
if (RCSTA & (_BV(OERR))) {printf ("1_RX_halt, overrun\r\n");RCSTA &= (~(1<<CREN));RCSTA |= (1<<CREN);} |
|
|
48 |
if (RCSTA & (1 << FERR)) printf ("1_RX_halt, frame error\r\n"); |
|
|
49 |
bit_2 = getc(); |
|
|
50 |
delay_ms(time); |
|
|
51 |
|
|
|
52 |
if (RCSTA & (1 << OERR)) {printf ("2_RX_halt, overrun\n\r");RCSTA &= (~(1<<CREN));RCSTA |= (1<<CREN);} |
|
|
53 |
if (RCSTA & (1 << FERR)) printf ("2_RX_halt, frame error\r\n"); |
|
|
54 |
bit_3 = getc(); |
|
|
55 |
delay_ms(time); |
|
|
56 |
|
|
|
57 |
if (RCSTA & (1 << OERR)) {printf ("3_RX_halt, overrun\r\n");RCSTA &= (~(1<<CREN));RCSTA |= (1<<CREN);} |
|
|
58 |
if (RCSTA & (1 << FERR)) printf ("3_RX_halt, frame error\r\n"); |
|
|
59 |
bit_4 = getc(); |
|
|
60 |
delay_ms(time); |
|
|
61 |
|
|
|
62 |
if (RCSTA & (1 << FERR)) printf ("4_RX_halt, frame error\r\n"); |
|
|
63 |
if (RCSTA & (1 << OERR)) {printf ("4_RX_halt, overrun\r\n");RCSTA &= (~(1<<CREN));RCSTA |= (1<<CREN);}; |
|
|
64 |
|
|
|
65 |
|
|
|
66 |
putc(bit_1); |
|
|
67 |
putc(bit_2); |
|
|
68 |
putc(bit_3); |
|
|
69 |
putc(bit_4); |
|
|
70 |
putc('\r'); |
|
|
71 |
putc('\n'); |
|
|
72 |
time = (bit_1 - 0x30) * 1000 + (bit_2 - 0x30)*100 + (bit_3 - 0x30)*10 + bit_4 - 0x30; |
|
|
73 |
if (time > 1000) time = 0; |
|
|
74 |
|
|
|
75 |
}; |
|
|
76 |
|
|
|
77 |
} |