|
TM1628 测试没有问题 gcc avr 网络上的程序 经过更改把里面的数据位更改过,,,自己用的时候 请自己更改查表值
//*****************************************************************************/
/*
编译环境,winavr 2004
内部 1 m
2011年10月25日21时00分58秒
*/
#include <avr/io.h>
#include <avr/delay.h>
#define uint unsigned int
#define uchar unsigned char
#define HIGH 1
#define LOW 0
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MSB 0x80
#define LSB 0x01
#define DECODE_MODE 0x09
#define INTENSITY 0x0A
#define SCAN_LIMIT 0x0B
#define SHUT_DOWN 0x0C
#define DISPLAY_TEST 0x0F
#define STB PB2
#define CLK PB1
#define DATA PB0
uchar address_1[]={0x01,0x02,0x04,0x08};
uchar dat_1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e}; //共阳
uchar address_2[]={0xfe,0xfd,0xfb,0xf8};
uchar dat_2[]={0xeb,0x41,0xe6,0x67,0x4d,0x2f,0xaf,0x61,0xef,0x6f,0xff,0xff,0xff,0xff,0xff,0xff,0x00}; //共阴
uint ad_data,i,k,l,num;
uint wanwei,qianwei,baiwei,shiwei,gewei;
void delay_ms(uint ms)
{
uint x,y;
for(x=0;x<ms;x++)
for(y=0;y<1141;y++);
}
//test program display from 1~
void Write_sm1628_byte(unsigned char temp)
{
unsigned char i,t;
for (i=0;i<8;i++)
{
t=(temp&LSB);
if(t==0x01)
PORTB|=(1<<DATA); //DIN
else
PORTB&=~(1<<DATA); //clk=0
PORTB&=~(1<<CLK);
temp>>=1;
PORTB|=(1<<CLK);
}
}
void Write_sm1628(unsigned char command)
{
PORTB&=~(1<<STB);
Write_sm1628_byte(command);
PORTB|=(1<<STB);
PORTB|=(1<<DATA);
}
void init_sm1628(void)
{
PORTB|=(1<<CLK);
PORTB|=(1<<STB);
PORTB|=(1<<DATA);
}
void display_1()
{
uint y,j=0;
Write_sm1628(0x03); //设置显示模式
Write_sm1628(0x40); //数据设置 //地址设定
PORTB&=~(1<<STB);
Write_sm1628_byte(0xc0);
for(y=0;y<4;y++)
{
Write_sm1628_byte(dat_2[j]);
Write_sm1628_byte(0xff);
j++;
}
PORTB|=(1<<STB);
Write_sm1628(0x8f);
j=0;
delay_ms(900);
PORTB&=~(1<<STB);
Write_sm1628_byte(0xc0);
Write_sm1628_byte(0x00);
Write_sm1628_byte(0x00);
for(y=0;y<3;y++)
{
Write_sm1628_byte(dat_2[j]);
Write_sm1628_byte(0xff);
j++;
}
PORTB|=(1<<STB);
j=0;
delay_ms(900);
PORTB&=~(1<<STB);
Write_sm1628_byte(0xc0);
Write_sm1628_byte(0x00);
Write_sm1628_byte(0x00);
Write_sm1628_byte(0x00);
Write_sm1628_byte(0x00);
for(y=0;y<2;y++)
{
Write_sm1628_byte(dat_2[j]);
Write_sm1628_byte(0xff);
j++;
}
PORTB|=(1<<STB);
j=0;
delay_ms(900);
PORTB&=~(1<<STB);
Write_sm1628_byte(0xc0);
Write_sm1628_byte(0x00);
Write_sm1628_byte(0x00);
Write_sm1628_byte(0x00);
Write_sm1628_byte(0x00);
Write_sm1628_byte(0x00);
Write_sm1628_byte(0x00);
Write_sm1628_byte(dat_2[j]);
Write_sm1628_byte(0xff);
PORTB|=(1<<STB);
j=3;
delay_ms(900);
PORTB&=~(1<<STB);
Write_sm1628_byte(0xc0);
Write_sm1628_byte(dat_2[j]);
Write_sm1628_byte(0xff);
Write_sm1628_byte(0x00);
Write_sm1628_byte(0x00);
Write_sm1628_byte(0x00);
Write_sm1628_byte(0x00);
Write_sm1628_byte(0x00);
Write_sm1628_byte(0x00);
PORTB|=(1<<STB);
j=2;
delay_ms(900);
PORTB&=~(1<<STB);
Write_sm1628_byte(0xc0);
for(y=0;y<2;y++)
{
Write_sm1628_byte(dat_2[j]);
Write_sm1628_byte(0xff);
j++;
}
Write_sm1628_byte(0x00);
Write_sm1628_byte(0x00);
Write_sm1628_byte(0x00);
Write_sm1628_byte(0x00);
PORTB|=(1<<STB);
j=1;
delay_ms(900);
PORTB&=~(1<<STB);
Write_sm1628_byte(0xc0);
for(y=0;y<3;y++)
{
Write_sm1628_byte(dat_2[j]);
Write_sm1628_byte(0xff);
j++;
}
Write_sm1628_byte(0x00);
Write_sm1628_byte(0x00);
PORTB|=(1<<STB);
delay_ms(900);
}
void display_2(uint m,uint n,uint k,uint l)
{
uint z;
Write_sm1628(0x03); //设置显示模式
Write_sm1628(0x40); //数据设置 //地址设定
for(z=0;z<5;z++)
{
PORTB&=~(1<<STB);
Write_sm1628_byte(0xc0);
Write_sm1628_byte(dat_2[l]);
Write_sm1628_byte(0xff);
Write_sm1628_byte(dat_2[k]);
Write_sm1628_byte(0xff);
Write_sm1628_byte(dat_2[n]);
Write_sm1628_byte(0xff);
Write_sm1628_byte(dat_2[m]);
Write_sm1628_byte(0xff);
PORTB|=(1<<STB);
}
//trans();
//display();
//init_display();
Write_sm1628(0x8f);
}
void main()
{
uint r;
DDRB=0xff;
init_sm1628();
for(r=0;r<3;r++)
{
display_1();
}
while(1)
{
num++;
display_2(num/1000,num/100%10,num/10%10,num%10);
delay_ms(100);
if(num==10000)
num=0;
}
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|