Hallo, ich benötige mal Eure Hilfe, ich versuche schon den ganzen Tag die Routine zur Ansteuerung eines 74HC595 ohne SPI ans laufen zu bekommen. Im Simulator sieht es gut aus, aber technisch kommt nichts an. Header:
1 | /* SERiell nach PArallel (serpa) im SPI-Protokoll */
|
2 | #ifndef _COM74HC595_H_
|
3 | #define _COM74HC595_H_
|
4 | |
5 | /* 4 Bytes (32 Ports) */
|
6 | #define COM74HC595_SIZE 1
|
7 | |
8 | #define PORT_COM74HC595 PORTB
|
9 | #define PORT_SER PB0 //74HC595 PIN 14
|
10 | #define PORT_SCK PB1 //74HC595 PIN 11
|
11 | #define PORT_RCK PB2 //74HC595 PIN 12
|
12 | |
13 | #define DDR_COM74HC595 DDRB
|
14 | #define DDR_SER DDB0 //74HC595 PIN 14
|
15 | #define DDR_SCK DDB1 //74HC595 PIN 11
|
16 | #define DDR_RCK DDB2 //74HC595 PIN 12
|
17 | |
18 | extern unsigned char com74hc595[]; |
19 | extern void Com74hc595_out(); |
20 | extern void Com74hc595_init(); |
21 | |
22 | #endif /* _COM74HC595_H_ */ |
Main:
1 | #include <avr/io.h> |
2 | #include "Com74hc595.h" |
3 | |
4 | /* Array fuer die Daten */
|
5 | unsigned char com74hc595[ COM74HC595_SIZE ]; |
6 | |
7 | void Com74hc595_init() |
8 | {
|
9 | /* Verwendete Ports auf OUT */
|
10 | DDR_COM74HC595 |= ( 1 << DDR_SER); |
11 | DDR_COM74HC595 |= ( 1 << DDR_SCK); |
12 | DDR_COM74HC595 |= ( 1 << DDR_RCK); |
13 | |
14 | |
15 | PORT_COM74HC595 &= ~(1<<PORT_SER); |
16 | /* SCR und RCK auf definierten Level HIGH */
|
17 | PORT_COM74HC595 |= (1<<PORT_SCK); |
18 | PORT_COM74HC595 |= (1<<PORT_RCK); |
19 | }
|
20 | |
21 | void Com74hc595_out() |
22 | {
|
23 | unsigned char anz = COM74HC595_SIZE; |
24 | unsigned char* serp = com74hc595 + COM74HC595_SIZE; |
25 | |
26 | do
|
27 | {
|
28 | unsigned char bits; |
29 | unsigned char data = *--serp; |
30 | |
31 | /* 8 Bits pro Byte rausschieben */
|
32 | for (bits = 8; bits > 0; bits--) |
33 | {
|
34 | PORT_COM74HC595 &= ~(1<<PORT_SER); |
35 | if (data & 0x80) |
36 | {
|
37 | PORT_COM74HC595 |= (1<<PORT_SER); |
38 | };
|
39 | |
40 | data <<= 1; |
41 | /* Strobe an SCK schiebt Daten im Gaensemarsch */
|
42 | /* um 1 Position weiter durch alle Schieberegister */
|
43 | PORT_COM74HC595 &= ~(1<<PORT_SCK); |
44 | PORT_COM74HC595 |= (1<<PORT_SCK); |
45 | }
|
46 | }
|
47 | while (--anz > 0); |
48 | |
49 | /* Strobe an RCK bringt die Daten von den Schieberegistern in die Latches */
|
50 | PORT_COM74HC595 &= ~(1<<PORT_RCK); |
51 | PORT_COM74HC595 |= (1<<PORT_RCK); |
52 | }
|
53 | |
54 | int main(void) |
55 | {
|
56 | Com74hc595_init(); |
57 | |
58 | com74hc595[0] = 0x1; |
59 | com74hc595[1] = 0x1; |
60 | com74hc595[2] = 0x1; |
61 | com74hc595[3] = 0x1; |
62 | com74hc595[4] = 0x0; |
63 | com74hc595[5] = 0x0; |
64 | com74hc595[6] = 0x0; |
65 | com74hc595[7] = 0x0; |
66 | |
67 | Com74hc595_out(); |
68 | |
69 | while(1) |
70 | {
|
71 | }
|
72 | |
73 | return 0; |
74 | }
|
Der Ursprungscode stammt übringends von hier: http://www.roboternetz.de/wissen/index.php/Portexpander_am_AVR#Makros.2C_Datenstrukturen.2C_Funktionen Danke für jeden Tip. Gruß Frank