#include
typedef signed char int8; //8位有符号字符型
typedef signed int int16; //16位有符号整型
typedef signed long int32; //32位有符号长整型
typedef unsigned char uint8; //8位无符号字符型
typedef unsigned int uint16; //16位无符号整型
typedef unsigned long uint32; //32位无符号长整型
sbit Segment_election = P2^5; //段选74HC573
sbit position_election = P2^6; //位选74HC573
sbit DATA_A_595 = P1^0; //74HC595 串行数据输入引脚
sbit SHIFT_CLOCK_595 = P1^4; //74HC595 移位寄存器时钟信号输入引脚
sbit LATCH_CLOCK_595 = P2^3; //74HC595 锁存器时钟信号输入引脚
void delay(uint16 x_ms); //延迟 x_ms*1 毫秒
void write_byte_74hc595(uint8 dat); //给595芯片写一字节数据函数
uint8 character;
uint8 code zifu[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf}; //共阳数码管编码表
void main()
{
P1=0XFF;
write_byte_74hc595(0X40); //给595芯片写一字节数据函数
write_byte_74hc595(0X00); //给595芯片写一字节数据函数 关掉595被控制的所有功能
//uint8 zifu[19]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0x89,0x7f,0xbf}; //共阳数码管编码表
character=0;
while(1)
{
Segment_election=0;
position_election=0;
P0=zifu[0];
Segment_election=1;
Segment_election=0;
Segment_election=0;
position_election=0;
P0=0X01;
position_election=1;
position_election=0;
delay(3);
//
Segment_election=0;
position_election=0;
P0=zifu[1];
Segment_election=1;
Segment_election=0;
Segment_election=0;
position_election=0;
P0= 0x02;
position_election=1;
position_election=0;
delay(3);
//
Segment_election=0;
position_election=0;
P0= (0xbf);
Segment_election=1;
Segment_election=0;
Segment_election=0;
position_election=0;
P0=0X04;
position_election=1;
position_election=0;
delay(3);
//
Segment_election=0;
position_election=0;
P0=zifu[1];
Segment_election=1;
Segment_election=0;
Segment_election=0;
position_election=0;
P0=0X08;
position_election=1;
position_election=0;
delay(3);
//
Segment_election=0;
position_election=0;
P0=zifu[2];
Segment_election=1;
Segment_election=0;
Segment_election=0;
position_election=0;
P0=0X10;
position_election=1;
position_election=0;
delay(3);
//
Segment_election=0;
position_election=0;
P0=(0xbf);
Segment_election=1;
Segment_election=0;
Segment_election=0;
position_election=0;
P0=0X20;
position_election=1;
position_election=0;
delay(3);
//
//
Segment_election=0;
position_election=0;
P0=zifu [2];
Segment_election=1;
Segment_election=0;
Segment_election=0;
position_election=0;
P0=0x40;
position_election=1;
position_election=0;
delay(3);
Segment_election=0;
position_election=0;
P0=zifu [9];
Segment_election=1;
Segment_election=0;
Segment_election=0;
position_election=0;
P0=0x80;
position_election=1;
position_election=0;
delay(3);
}
}
void write_byte_74hc595(uint8 dat) //给595芯片写一字节数据函数
{
uint8 i;
for(i=0;i<8;i++)
{
DATA_A_595 =(dat<
SHIFT_CLOCK_595 = 0; //74HC595 移位寄存器时钟信号输入引脚
SHIFT_CLOCK_595 = 1; //74HC595 移位寄存器时钟信号输入引脚
}
LATCH_CLOCK_595 = 0; //74HC595 锁存器时钟信号输入引脚
LATCH_CLOCK_595 = 1; //74HC595 锁存器时钟信号输入引脚
}
void delay(uint16 x_ms) //延迟 x_ms*1 毫秒
{
uint16 i,j;
for(i=x_ms;i>0;i--)
for(j=114;j>0;j--);
}