Subversion Repositories group.electronics

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
128 pfowler 1
/*
2
 * hc595.c
3
 *
4
 *  Created on: 16/07/2014
5
 *      Author: pfowler
6
 */
7
 
8
#include <avr/io.h>
9
#include <avr/wdt.h>
10
#include <avr/interrupt.h>
11
#include <string.h>
12
#include <util/delay.h>
13
#include <stdlib.h>
14
 
15
#include "config.h"
16
#include "hc595.h"
17
#include "avrutil.h"
18
 
19
// The delay to use after sending the store line pulse
20
#define HC595_STCP_DELAY		1
21
 
22
/*
23
 * Configure the 595 pins as outputs
24
 */
25
void hc595_init() {
26
	HC595_DDR|=((1<<HC595_SHCP_PIN)|(1<<HC595_STCP_PIN)|(1<<HC595_DS_PIN));
27
}
28
 
29
/*
30
 * Pulse the clock line
31
 */
32
void hc595_pulse() {
33
	sbi(HC595_PORT, HC595_SHCP_PIN);
34
	cbi(HC595_PORT, HC595_SHCP_PIN);
35
}
36
 
37
/*
38
 * Pulse the store line
39
 */
40
void hc595_latch() {
41
	sbi(HC595_PORT, HC595_STCP_PIN);
42
	//_delay_us(HC595_STCP_DELAY);
43
	cbi(HC595_PORT, HC595_STCP_PIN);
44
}
45
 
46
void hc595_write(uint8_t data) {
47
	uint8_t i;
48
	for (i = 0; i<8; i++) {
49
		if (rbi(data, i))
50
			sbi(HC595_PORT, HC595_DS_PIN);
51
		else
52
			cbi(HC595_PORT, HC595_DS_PIN);
53
		hc595_pulse();
54
	}
55
	hc595_latch();
56
}