Rev 134 | Blame | Compare with Previous | Last modification | View Log | RSS feed
/** hc595.c** Created on: 16/07/2014* Author: pfowler*/#include <avr/io.h>#include <avr/wdt.h>#include <avr/interrupt.h>#include <string.h>#include <util/delay.h>#include <stdlib.h>#include "config.h"#include "hc595.h"#include "avrutil.h"// The delay to use after sending the store line pulse#define HC595_STCP_DELAY 1/** Configure the 595 pins as outputs*/void hc595_init() {HC595_DDR|=((1<<HC595_SHCP_PIN)|(1<<HC595_STCP_PIN)|(1<<HC595_DS_PIN));}/** Pulse the clock line*/void hc595_pulse() {sbi(HC595_PORT, HC595_SHCP_PIN);cbi(HC595_PORT, HC595_SHCP_PIN);}/** Pulse the store line*/void hc595_latch() {sbi(HC595_PORT, HC595_STCP_PIN);//_delay_us(HC595_STCP_DELAY);cbi(HC595_PORT, HC595_STCP_PIN);}void hc595_write(uint8_t data) {uint8_t i;for (i = 0; i<8; i++) {if (rbi(data, i))sbi(HC595_PORT, HC595_DS_PIN);elsecbi(HC595_PORT, HC595_DS_PIN);hc595_pulse();}hc595_latch();}