仿真图和程序如下,求大神解答啊,本人新手啊。。。
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit H1_shcp = P2^4; //HC595
芯片
sbit H1_stcp = P2^5;
sbit H_oe = P2^6;
sbit H_ds1 = P2^0;
sbit H_ds2 = P2^1;
sbit H_ds3 = P2^2;
sbit H_ds4 = P2^3;
sbit A = P1^0;
sbit D = P1^1;
sbit C =P1^2;
//sbit U5_shcp =P2^1;
//sbit U5_stcp =P2^2;
//sbit U5_oe =P2^3;
//sbit U5_ds=P2^0;
sbit HC138_G = P1^7; //HC138芯片
sbit E1 = P1^3;
sbit E2 = P1^4;
uchar data_j[] = {0x00,0x00,0x18,0x3c,0x5a,0x18,0x18,0x00}; //箭头
uchar data_t[] = {0x00,0x00,0x18,0x3c,0x5a,0x18,0x18,0x00}; //桃心
uchar data_k[]= {0x00,0x00,0x18,0x3c,0x5a,0x18,0x18,0x00};
uchar data_l[]={0x00,0x00,0x18,0x3c,0x5a,0x18,0x18,0x00};
//------------------------------------------------------------------
void delaxms(uint xms)
{
uint i, j;
for(i = xms; i > 0; i--) for(j = 118; j > 0; j--);
}
//------------------------------------------------------------------
void sendbyte_H1(uchar aa) //利用HC595输出
{
uchar z;
for(z = 0; z < 8; z++) { //循环8次移入数据
H1_shcp = 0;
H_ds1 = aa & 0x01; //数据低位送到HC595数据线
H1_shcp = 1; //上升沿输入数据
aa >>= 1;
/*else
{
U5_shcp=0;
U5_ds=aa& 0x01;
U5_shcp = 1;
aa >>= 1;
}*/ //右移一位
}
H1_stcp = 0;
H1_stcp = 1;
// U5_stcp = 0;
// U5_stcp=1; //上升沿使数据并行输出
}
void sendbyte_H2(uchar bb) //利用HC595输出
{
uchar m;
for(m = 0; m < 8; m++) { //循环8次移入数据
H1_shcp=0;
H_ds2=bb& 0x01;
H1_shcp = 1;
bb >>= 1;
//右移一位
}
H1_stcp = 0;
H1_stcp = 1;
// U5_stcp = 0;
// U5_stcp=1; //上升沿使数据并行输出
}
//------------------------------------------------------------------
void main()
{
uint i, r,k;
while(1) {
for(r = 30; r > 0; r--) { //显示箭头
for(i = 0; i < 8; i++) {
E1=1;
E2=0;
A=0;
D=0;
C=0;
HC138_G = 1; //关闭138,关闭显示
sendbyte_H1(data_l[i]); //输出箭头信息
sendbyte_H2(data_k[i]);
//P1 = 0xd8 | i; //换行
P1=P1+i;
//U5_oe=0;
HC138_G = 0; //打开显示
delaxms(1); //显示的时间
if(i==7)
{
E1=~E1;
E2=~E2;
}
}
/* for(r = 10; r > 0; r--) { //显示空白
for(i = 0; i < 8; i++) {
HC138_G = 1; //关闭138,关闭显示
sendbyte_H(0); //输出0
P1 = 0xd8 | i; //换行
HC138_G = 0; //打开显示
delaxms(5); //显示的时间
} } */
//for(r = 30; r > 0; r--) { //显示桃心
for(k = 0; k < 8; k++) {
A=0;
D=0;
C=0;
HC138_G = 1; //关闭138,关闭显示
sendbyte_H1(data_t[k]); //输出箭头信息
sendbyte_H2(data_j[k]);
// P1 = 0xd8 | k; //换行
P1=P1+k;
H_oe=0;
HC138_G = 0; //打开显示
delaxms(1); //显示的时间
if( k==7)
{
E1=~E1;
E2=~E2;
}
}
}// }
/* for(r = 10; r > 0; r--) { //显示空白
for(i = 0; i < 8; i++) {
HC138_G = 1; //关闭138,关闭显示
sendbyte_H(0); //输出0
P1 = 0xd8 | i; //换行
HC138_G = 0; //打开显示
delaxms(5); //显示的时间
} } */ }
}
-
-
-
一周热门 更多>