/*
PORTA.0 = Data DS
PORTA.1 = Latch STCP
PORTA.2 = Shift SHCP
*/
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
void HC595write(unsigned char udata){
unsigned char i;
i = 7;
while(i<=7){
PORTA = (udata >> i) & 0x01;// DATA
PORTA |= 0b00000100; // SHIFT 1
PORTA &= 0b11111011; // SHIFT 0
i--;
}
}
void HC595write_2byte(unsigned int udata){
unsigned char digit[10] = {
0b11111100, //0
0b01100000, //1
0b11011010, //2
0b11110010, //3
0b01100110, //4
0b10110110, //5
0b00111110, //6
0b11100100, //7
0b11111110, //8
0b11100110 //9
};
PORTA &= 0b11111110; // DATA 0
PORTA &= 0b11111011; // SHIFT 0
PORTA &= 0b11111101; // LATCH 0
unsigned char d10 = digit[udata/10];
unsigned char d1 = digit[udata%10];
HC595write(~d10);
HC595write(~d1);
PORTA |= 0b00000010; // LATCH 0
PORTA &= 0b11111101; // LATCH 1
}
int main(void){
DDRA = 0xFF;
unsigned int num_buf = 0;
while(1){
HC595write_2byte(num_buf);
_delay_ms(200);
num_buf++;
if(num_buf>99) num_buf = 0;
}
}