Last change
on this file was 12143, checked in by neise, 13 years ago |
Arduinocode for Arduino-Microcontroller to communicate with PLD
|
File size:
1.2 KB
|
Line | |
---|
1 |
|
---|
2 | unsigned char ReadFromDataBus(){
|
---|
3 | // The eight bits of the databus are distributed over
|
---|
4 | // the two differen ports of the ATmega. Port C and D
|
---|
5 | // actually they are connected like this:
|
---|
6 | // data0...data3 are connected to Arduino Pins D4..D7
|
---|
7 | // data4...data7 are connected to Arduino Pins C0..D3
|
---|
8 | return ( (PINC&0x0f) << 4 ) | ( (PIND&0xf0) >> 4) ;
|
---|
9 | }
|
---|
10 |
|
---|
11 | void PutOnDataBus ( unsigned char data) {
|
---|
12 | // okay .. .again
|
---|
13 | // data0..3 is connected to PD4..7
|
---|
14 | // data4..7 is connected to PC0..3
|
---|
15 | PORTC = (PORTC & 0xf0) | (data&0xf0)>>4 ;
|
---|
16 | PORTD = (PORTD & 0x0f) | (data&0x0f)<<4 ;
|
---|
17 | }
|
---|
18 |
|
---|
19 |
|
---|
20 | void MakeDataBusOutput() {
|
---|
21 | // making the databus out can be done like this:
|
---|
22 | // data0..3 is connected to PD4..7
|
---|
23 | // data4..7 is connected to PC0..3
|
---|
24 |
|
---|
25 | // also auf PORTC die bits 0 bis 3 setzen!
|
---|
26 | DDRC |= 0x0f;
|
---|
27 | // und auf PORTD die bits 4 bis 7 setzen!
|
---|
28 | DDRD |= 0xf0;
|
---|
29 |
|
---|
30 | // Um die Pullups muss man sicht nicht kümmern, da nach dieser Funktion sowieso ein neuer Wert auf den Bus
|
---|
31 | // geschrieben wird.
|
---|
32 | }
|
---|
33 |
|
---|
34 | void MakeDataBusInput() {
|
---|
35 | // see the comments in MakeDataBusOutput()
|
---|
36 |
|
---|
37 | //first we switch the outs to ins
|
---|
38 | // then we switch on the pullups
|
---|
39 |
|
---|
40 | DDRC &= 0xf0;
|
---|
41 | DDRD &= 0x0f;
|
---|
42 | // now the pull ups
|
---|
43 | PORTC |= 0x0f;
|
---|
44 | PORTD |= 0xf0;
|
---|
45 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.