/[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 109 - (hide annotations) (download)
Mon May 28 10:13:48 2007 UTC (17 years, 1 month ago) by hedin
File MIME type: text/plain
File size: 2536 byte(s)
Integrated barcode & keyboard modules
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    
32     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     TXSTA = 0x24; // TXSTA7 = 0 Don't care in asynchronous
39     // TXSTA6 = 0 8-bit transmission
40     // TXSTA5 = 1 Transmit enabled
41     // TXSTA4 = 0 Asynchronous mode
42     // TXSTA3 = 0 Unimplemented
43     // TXSTA2 = 1 High speed
44     // TXSTA1 = 0 TSR empty
45     // TXSTA0 = 0 9th bit
46     RCSTA = 0x90; // RCSTA7 = 0 Serial port disabled
47     // RCSTA6 = 0 8-bit reception
48     // RCSTA5 = 0 Don't care in asynchronous
49     // RCSTA4 = 1 Receiver enabled
50     // RCSTA3 = 0 Don't care (8-bit operation)
51     // RCSTA2 = 0 No framing error
52     // RCSTA1 = 0 Overrun error bit
53     // RCSTA0 = 0 9th bit
54    
55     //config completed
56     SPEN = 1; //Enable Serial port
57    
58     //Set module-scope variables
59     barcode_length = 0;
60     barcode_ready = 0;
61    
62     //Configure interrupts
63     TXIE = 0; //Disable AUX TX interrupt - testes med TXIF;
64     RCIE = 1; //Enable AUX Recieve interrupt - testes med RCIF;
65    
66     IPEN = 0; // IPEN=Interrupt Priority ENable bit - her bruges ingen prioritet
67    
68     PEIE = 1; // PEIE = PEriphal Interrupt Enable
69    
70     TXIF = 0; //nulstil intterupt flag
71     RCIF = 0;
72    
73     GIE = 1; //Global interrupt enable bit
74    
75     }
76    
77     void barcode_reset(void)
78     {
79     barcode_length = 0;
80     barcode_ready = 0;
81     }
82    
83     unsigned char barcode_is_ready(void)
84     {
85     return barcode_ready;
86     }
87    
88     unsigned char barcode_get_length()
89     {
90     return barcode_length;
91     }
92    
93     /* interrupt entry function - barcode is the only module using interrupts */
94     void /*interrupt*/ barcode_interrupt(void)
95     {
96     char data = RCREG;
97     RCIF = 0;
98    
99     if (barcode_ready == 0)
100     {
101     if (data == '\r')
102     {
103     return;
104     }
105     else if (data == '\n')
106     {
107     barcode_ready = 1;
108     }
109     else
110     {
111     global_barcode_buffer[barcode_length++] = RCREG;
112     }
113     }
114    
115    
116    
117    
118     }

  ViewVC Help
Powered by ViewVC 1.1.20