1 | /** I N C L U D E S ********************************/
|
2 | #include <p18f46K20.h>
|
3 | #include <usart.h>
|
4 | #include <adc.h>
|
5 | #include <delays.h>
|
6 | #include <stdlib.h>
|
7 |
|
8 | /** Configuration Word ******************************
|
9 | *
|
10 | * PIC18F46K20 mit externem Quarz.
|
11 | *
|
12 | */
|
13 | #pragma config FOSC = HS
|
14 | #pragma config FCMEN = OFF
|
15 | #pragma config IESO = OFF
|
16 | #pragma config PWRT = OFF
|
17 | #pragma config BOREN = OFF
|
18 | #pragma config BORV = 30
|
19 | #pragma config WDTEN = OFF
|
20 | #pragma config WDTPS = 32768
|
21 | #pragma config MCLRE = ON
|
22 | #pragma config LPT1OSC = OFF
|
23 | #pragma config PBADEN = OFF
|
24 | // #pragma config CCP2MX = ON
|
25 | #pragma config STVREN = ON
|
26 | #pragma config LVP = OFF
|
27 | // #pragma config ICPRT = OFF // Dedicated In-CircuitDebug/Programming
|
28 | #pragma config XINST = OFF // Extended Instruction Set
|
29 | #pragma config CP0 = OFF
|
30 | #pragma config CP1 = OFF
|
31 | // #pragma config CP2 = OFF
|
32 | // #pragma config CP3 = OFF
|
33 | #pragma config CPB = OFF
|
34 | // #pragma config CPD = OFF
|
35 | #pragma config WRT0 = OFF
|
36 | #pragma config WRT1 = OFF
|
37 | // #pragma config WRT2 = OFF
|
38 | // #pragma config WRT3 = OFF
|
39 | #pragma config WRTB = OFF // Boot Block Write Protection
|
40 | #pragma config WRTC = OFF
|
41 | // #pragma config WRTD = OFF
|
42 | #pragma config EBTR0 = OFF
|
43 | #pragma config EBTR1 = OFF
|
44 | // #pragma config EBTR2 = OFF
|
45 | // #pragma config EBTR3 = OFF
|
46 | #pragma config EBTRB = OFF
|
47 |
|
48 | /** D E C L A R A T I O N S ********************/
|
49 | #pragma code
|
50 |
|
51 | /** F U N C T I O N S **************************/
|
52 |
|
53 | // **********************************************
|
54 | //
|
55 | // Hauptprogramm
|
56 | //
|
57 | // **********************************************
|
58 | void main()
|
59 | {
|
60 | char str[20];
|
61 |
|
62 | //Einstellen der Ports
|
63 | // 0 = Output
|
64 | // 1 = Input
|
65 | TRISD = 0x0F; // PORT D
|
66 | TRISC = 0x00; // PORT C Ausgang
|
67 |
|
68 | // USART Einstellen
|
69 | OpenUSART( USART_TX_INT_OFF &
|
70 | USART_RX_INT_OFF &
|
71 | USART_ASYNCH_MODE &
|
72 | USART_EIGHT_BIT &
|
73 | USART_CONT_RX &
|
74 | USART_BRGH_LOW, 18 );
|
75 |
|
76 | // ADC Einstellen
|
77 | OpenADC( ADC_FOSC_32 &
|
78 | ADC_RIGHT_JUST &
|
79 | ADC_12_TAD,
|
80 | ADC_CH5 &
|
81 | ADC_INT_OFF, 15 );
|
82 |
|
83 | while(1) {
|
84 |
|
85 | // Nur ausführen wenn Taster gedrückt wird.
|
86 | if( PORTDbits.RD0 == 0 )
|
87 | {
|
88 | SetChanADC( ADC_CH5 );
|
89 |
|
90 | Delay10TCYx( 5 );
|
91 | ConvertADC();
|
92 | while( BusyADC() ); // Warten bis A/D Wandler fertig ist.
|
93 |
|
94 | ultoa( ADRESH, str );
|
95 | putsUSART( str );
|
96 | while( BusyUSART() );
|
97 | ultoa( ADRESL, str );
|
98 | putsUSART( str );
|
99 | while( BusyUSART() );
|
100 | WriteUSART( 0x0D ); // Zeilenanfang
|
101 | while( BusyUSART() );
|
102 | WriteUSART( 0x0A ); // Neue Zeile
|
103 | while( BusyUSART() );
|
104 |
|
105 | while( PORTDbits.RD0 == 0); // Erst weiter wenn Taste Losgelassen wird.
|
106 | Delay10TCYx( 5 ); // Entprellen
|
107 | PORTDbits.RD7 ^= 1;
|
108 | }
|
109 | }
|
110 |
|
111 | // Programmende
|
112 | }
|