您的位置 首页 IOT

单片机SPI模块+74LS164驱动数码管

效果如下:循环右移再左移#includehtc.h>#ifndef_XTAL_FREQ#define_XTAL_FREQ4000000#endifconstunsignedcharseg_com

作用如下:循环右移再左移

#include
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 4000000
#endif
const unsigned char seg_comAnode[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f};//共阳
const unsigned char seg_comCathode[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,
0x87,0xff,0xef}; //共阴
/*一起发送和接纳一个字节,74LS164吸电流大于拉电流,数码管接成上拉方式*/
unsigned char BUFF;
void init(){
TRISC=0B11010111;/*RC4/SDI引脚为输出,RC5/SDO引脚为输出,从形式RC3/SCK引脚为输入*/
SSPSTAT=0b00000000;/* 在结束时采样,在上升沿数据移位*/
SSPCON=0b00110010;/* SSPEN=1;CKP=1 , FOSC/64,*/
TRISD=0X00;
PORTD=0;
}
void In_74LS164(unsigned char datas){
SSPBUF=datas;
do
{
;
}while(SSPIF==0);/*等候发送结束*/
SSPIF=0;/*铲除SSPIF标志*/
//BUFF=SSPBUF;/*腾空缓冲器*/
}
void main()
{unsigned char b,a,i,s=0;unsigned char m=0x01;
init();
while(1){

for(i=0;i<4;i++)
{
PORTD=~(m<for(s=0;s<9;s++){

In_74LS164( seg_comCathode[s]);
__delay_ms(100);__delay_ms(100);
}
}

for(i=1,a=m<<4;i<4;i++)
{
PORTD=~(a>>i);

for(s=0;s<9;s++){

In_74LS164( seg_comCathode[s]);
__delay_ms(100);__delay_ms(100);
}
}
}
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/yingyong/iot/252390.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部