#include "led.h"
#include "sfr_R8C2Lconfig.h" /* Definition of R8C/2L SFR */
unsigned char led_reg = 0;
unsigned char tab[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,
// 0, 1 ,2, 3, 4, 5, 6, 7, 8, 9,
0x79, 0x71, 0x76, 0x73, 0xff};
// E, F, H, P, all
void TA6932_Write(unsigned char DATA) //写数据函数
{
unsigned char i;
for(i=0;i<8;i++)
{
CLK=0; //上升沿
if(DATA&0X01)
DIN=1;
else
DIN=0;
DATA>>=1;//LSB first, MSB last
CLK=1;
}
}
void Write_COM(unsigned char cmd) //发送命令字
{
STB=0;
TA6932_Write(cmd);
STB=1;
}
//add from 00h to 0fh
void Write_DATA(unsigned char add,unsigned char DATA) //指定地址写入数据
{
Write_COM(0x44); //0100 0100 固定地址
STB=0;
TA6932_Write(0xc0|add);//1100 0000 | addr
TA6932_Write(DATA);
STB=1;
}
void init_TA6932(void)
{
unsigned char i;
Write_COM(0x8a);//亮度1000 1010
Write_COM(0x40); //写 数据命令0100 0000
STB=0;
TA6932_Write(0xc0); //写地址命令1100 0000
for(i=0; i<11; i++)
//TA6932_Write(0x00);
Write_DATA(i, 0x00); //make led to show nothing
STB=1;
delay(10);
open_all();
delay(100);
close_all();
}
void display(unsigned char led, unsigned char number)
{
Write_DATA(led, number);
}
void turn_on_led(unsigned char number)
{
led_reg |= number;
Write_DATA(0x0B, led_reg); //grid 11
}
void turn_off_led(unsigned char number)
{
led_reg&= ~number;
Write_DATA(0x0B, led_reg); //grid 11
}
void open_all(void)
{
unsigned char i;
for(i=0; i<11; i++)
Write_DATA(i, 0xFF);
led_reg = 0xff;
}
void close_all(void)
{
unsigned char i;
for(i=0; i<11; i++)
Write_DATA(i, 0x00);
led_reg = 0x00;
}
void delay(unsigned char number)
{
unsigned char i = 0, j = 0;
for (j = 0; j < number; j++)
{
for (j = 0; j < 200; j++)
{}
}
}
评论9
最新资源