/[H8]/trunk/PIC/Demo trimmet/barcode.c
ViewVC logotype

Annotation of /trunk/PIC/Demo trimmet/barcode.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 111 - (hide annotations) (download)
Mon May 28 15:00:55 2007 UTC (17 years, 1 month ago) by hedin
File MIME type: text/plain
File size: 2586 byte(s)
embedded 1.0 rc1
1 hedin 109 #include <pic18.h>
2    
3     #include "barcode.h"
4    
5    
6     /*************************
7     globals
8     ************************/
9     char global_barcode_buffer[14];
10    
11    
12     /***********************
13     module vars
14     *************************/
15    
16     unsigned char barcode_length;
17     bit barcode_ready;
18    
19     /*************************
20     function
21     *************************/
22    
23     void barcode_init(void)
24     {
25     SPEN = 0; //Make sure serial port is disabled
26    
27     // snupset fra Kim H Pedersens serialmain.c
28     // Set Port C bit 6 output (TxD) and bit 7 input (RxD)
29     TRISC6 = 0;
30     TRISC7 = 1;
31 hedin 111 /*
32 hedin 109 SPBRG = 25; // x = Fosc/(16 * Baud Rate) - 1
33     // x = 4000000/(16 * 9600) - 1
34     // x = 25.0417 ~ 25
35     // Baud Rate = Fosc/(16 * (x+1))
36     // Baud Rate = 4000000/(16 * (25+1))
37     // Baud Rate = 9615
38 hedin 111 */
39    
40     SPBRG = 130; //BRG værdi for 20Mhz MCU
41 hedin 109 TXSTA = 0x24; // TXSTA7 = 0 Don't care in asynchronous
42     // TXSTA6 = 0 8-bit transmission
43     // TXSTA5 = 1 Transmit enabled
44     // TXSTA4 = 0 Asynchronous mode
45     // TXSTA3 = 0 Unimplemented
46     // TXSTA2 = 1 High speed
47     // TXSTA1 = 0 TSR empty
48     // TXSTA0 = 0 9th bit
49     RCSTA = 0x90; // RCSTA7 = 0 Serial port disabled
50     // RCSTA6 = 0 8-bit reception
51     // RCSTA5 = 0 Don't care in asynchronous
52     // RCSTA4 = 1 Receiver enabled
53     // RCSTA3 = 0 Don't care (8-bit operation)
54     // RCSTA2 = 0 No framing error
55     // RCSTA1 = 0 Overrun error bit
56     // RCSTA0 = 0 9th bit
57    
58     //config completed
59     SPEN = 1; //Enable Serial port
60    
61     //Set module-scope variables
62     barcode_length = 0;
63     barcode_ready = 0;
64    
65     //Configure interrupts
66     TXIE = 0; //Disable AUX TX interrupt - testes med TXIF;
67     RCIE = 1; //Enable AUX Recieve interrupt - testes med RCIF;
68    
69     IPEN = 0; // IPEN=Interrupt Priority ENable bit - her bruges ingen prioritet
70    
71     PEIE = 1; // PEIE = PEriphal Interrupt Enable
72    
73     TXIF = 0; //nulstil intterupt flag
74     RCIF = 0;
75    
76     GIE = 1; //Global interrupt enable bit
77    
78     }
79    
80     void barcode_reset(void)
81     {
82     barcode_length = 0;
83     barcode_ready = 0;
84     }
85    
86     unsigned char barcode_is_ready(void)
87     {
88     return barcode_ready;
89     }
90    
91     unsigned char barcode_get_length()
92     {
93     return barcode_length;
94     }
95    
96     /* interrupt entry function - barcode is the only module using interrupts */
97     void /*interrupt*/ barcode_interrupt(void)
98     {
99     char data = RCREG;
100     RCIF = 0;
101    
102     if (barcode_ready == 0)
103     {
104     if (data == '\r')
105     {
106     return;
107     }
108     else if (data == '\n')
109     {
110     barcode_ready = 1;
111     }
112 hedin 111 else
113 hedin 109 {
114     global_barcode_buffer[barcode_length++] = RCREG;
115     }
116     }
117     }

  ViewVC Help
Powered by ViewVC 1.1.20