#include <mega128.h>
#include <delay.h>
#define sbi(x,y) (x |= (1<<y))
#define cbi(x,y) (x &= ~(1<<y))
#define tbi(x,y) (x & (1<<y))
#define DDR_CONF DDRB
#define PORT_CONF PORTB
#define A0 0
#define A1 1
#define A2 2
#define A3 3
#define WR 4
#define CONT_ALL (A0 | A1 | A2 | A3 | WR)
#define DDR_DATA DDRA
#define PORT_DATA PORTA
#define D0 0
#define D1 1
#define D2 2
#define D3 3
#define D4 4
#define D5 5
#define D6 6
#define D7 7
#define DATA_ALL (0xFF)
#define WR_HIGH() sbi(PORT_CONF, WR);
#define WR_LOW() cbi(PORT_CONF, WR);
#define VFD_CLEAR 0x80
#define VFD_CTR_MODE 0x10
#define VFD_CHAR_MODE 0x18
#define VFD_BRIGHT100 0
#define VFD_BRIGHT80 1
#define VFD_BRIGHT53 2
#define VFD_BRIGHT40 3
#define VFD_BRIGHT27 4
#define VFD_BRIGHT20 5
#define VFD_BRIGHT13 6
#define VFD_BRIGHT0 7
void VFDData(unsigned char _Data)
{
delay_us(1);
WR_HIGH();
PORT_DATA = _Data;
WR_LOW();
delay_us(1);
WR_HIGH();
}
void VFD_Char(unsigned char _Addr, unsigned char _Data)
{
sbi(PORT_CONF, A3);
PORT_CONF = (PORT_CONF & ~(0x07)) | _Addr;
VFDData(_Data);
}
void VFD_Performance(unsigned char _flag, unsigned int _delay)
{
cbi(PORT_CONF, A3);
if(_flag)
{
VFDData(VFD_BRIGHT100);
delay_ms(_delay);
VFDData(VFD_BRIGHT80);
delay_ms(_delay);
VFDData(VFD_BRIGHT53);
delay_ms(_delay);
VFDData(VFD_BRIGHT40);
delay_ms(_delay);
VFDData(VFD_BRIGHT27);
delay_ms(_delay);
VFDData(VFD_BRIGHT20);
delay_ms(_delay);
VFDData(VFD_BRIGHT13);
delay_ms(_delay);
}
else
{
VFDData(VFD_BRIGHT13);
delay_ms(_delay);
VFDData(VFD_BRIGHT20);
delay_ms(_delay);
VFDData(VFD_BRIGHT27);
delay_ms(_delay);
VFDData(VFD_BRIGHT40);
delay_ms(_delay);
VFDData(VFD_BRIGHT53);
delay_ms(_delay);
VFDData(VFD_BRIGHT80);
delay_ms(_delay);
VFDData(VFD_BRIGHT100);
delay_ms(_delay);
}
cbi(PORT_CONF, A3);
}
void main(void)
{
delay_ms(100);
DDR_CONF = 0x1F;
DDR_DATA = 0xFF;
PORT_CONF = 0x00;
PORT_DATA = 0x00;
VFDData(VFD_CLEAR|VFD_BRIGHT100);
sbi(PORT_CONF, A3);
while(1)
{
VFD_Char(0, '1');
VFD_Char(1, '2');
VFD_Char(2, '3');
VFD_Char(3, '4');
VFD_Char(4, '5');
VFD_Char(5, '6');
VFD_Char(6, '7');
VFD_Char(7, '8');
VFD_Performance(0, 200);
VFD_Performance(1, 200);
}
}
|