//功能1: 在数码管上显示字符串
void STC_SEG7_ShowString(const char *str)
{
uchar len,pos;
stc_buff = 0x37;
stc_buff = 0x53;
stc_buff = 0x45;
stc_buff = 0x47;
stc_buff = 0x53;
stc_buff = 0x00;
stc_buff = 0x00;
stc_buff = 0x00;
pos=8,len=0;
while(*str)
{
if(*str == '.')
{
if(stc_buff == '.')//如果上一位是点,则跳过
{
str++;
continue;
}
stc_buff = *str++; //否则添加点,但是不算位数
}
else
{
stc_buff = *str++;
len++;
if(len >=8)
{
if(*str == '.')
stc_buff = *str;
break;
}
}
}
stc_buff = 0;
UartSendData(stc_buff,pos+1);
} 测试发送:seg1.2.3..4.5.6.7.8.,能正常在数码管上显示
接下来实现控制DIP40的LED状态
命令说明里面是可以单独对P0~P5的指定端口,库函数并没有实现这一点
我们自己的函数加上这个功能
实现STC_LED40_SendData函数
dat为操作管脚的数组,size为dat的长度,port为指定的管脚
port P0~P5端口的屏蔽位(bit0:P0, bit1:P1, ...)
//功能: 控制DIP40的各个管脚上LED的状态
void STC_LED40_SendData(const char *dat,uchar size,uchar port)
{
if (size > 6)
size = 6;
stc_buff = 0x4c;
stc_buff = 0x45;
stc_buff = 0x44;
stc_buff = 0x28;
stc_buff = size+1;
stc_buff = port;
memcpy(stc_buff+6,dat,size);
UartSendData(stc_buff,size+6);
} 添加测试函数,简单的流水灯
//测试 STC_LED40_SendData
void Test_STC_LED40()
{
char buff;
uchar n;
for(n=0;n<8;n++)
{
memset(buff,~(0x01<<n),6);
STC_LED40_SendData(buff,6,0xff);
Delay_ms(500);
}
} 测试功能正常! 数码管/LED的代码: LED60和LED40一样,只用把头信息中的第四位0x28改为0x40,长度判断改为8即可
//功能: 控制DIP60的各个管脚上LED的状态
void STC_LED60_SendData(const char *dat,uchar size,uchar port)
{
if (size > 8)
size = 8;
stc_buff = 0x4c;
stc_buff = 0x45;
stc_buff = 0x44;
stc_buff = 0x40;
stc_buff = size+1;
stc_buff = port;
memcpy(stc_buff+6,dat,size);
UartSendData(stc_buff,size+6);
}
页:
1
[2]