All pastes #2055873 Raw Edit

Unnamed

public text v1 · immutable
#2055873 ·published 2011-05-09 19:37 UTC
rendered paste body
/* display.c - interface to VFD displays */

#include <inttypes.h>
#include <avr/io.h>
#include <util/delay_basic.h>

#include "config.h"
#include "display.h"

inline void push_bit(uint8_t b) {
	if(b)
		SHREG_PORT |=  (1 << SHREG_DATA);
	else
		SHREG_PORT &= ~(1 << SHREG_DATA);

	SHREG_PORT |= (1 << SHREG_SCLOCK);
	_delay_loop_1(CLOCK_DELAY);
	SHREG_PORT &= ~(1 << SHREG_SCLOCK);	
}

void push_data(uint8_t digit0, uint8_t digit1, uint8_t digit2, uint8_t digit3, uint8_t dots, uint8_t vfd) {
	uint8_t m;

	push_bit(vfd == 3);
	push_bit(vfd == 2);

	for(m=0b001000000; m; m >> 1)
		push_bit(digit3 & m);


	push_bit(dots);

	for(m=0b01000000; m; m >> 1)
		push_bit(digit2 & m);


	push_bit(vfd == 1);
	push_bit(vfd == 0);

	for(m=0b00100000; m; m >> 1)
		push_bit(digit1 & m);

	push_bit(dots);

	for(m=0b01000000; m; m >> 1)
		push_bit(digit0 & m);


	SHREG_PORT |= (1 << SHREG_LCLOCK);
	_delay_loop_1(CLOCK_DELAY);
	SHREG_PORT &= ~(1 << SHREG_LCLOCK);
}