单片机流水单C语言程序,单片机C语言程序举例(一)

原标题:单片机C语言程序举例(一)

本着共同学习,共同进步的目的,把我搞到的资料不辞辛苦的发上来,供初学者参考,希望可以对大家有帮助!所有程序是本人买 www.doflye.cn 上海浩豚电子科技的开发板赠送的。

1.流水灯C程序

#include

void delay(unsigned int cnt) //简单的延时

{

while(--cnt);

}

///

main()

{

P1=0xfe;//给初始化值

while(1)

{

delay(30000);//delay at crystal frequency in 12MHz

P1<<=1;//左移一位

P1|=0x01;//最后一位补1

if(P1==0x7f)//检测是否移到最左端?

{

delay(30000);//delay

P1=0xfe;

}

}

}

2.数码管动态扫描C程序

#include

unsigned char const dofly[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};// 显示段码值01234567

unsigned char code seg[]={0,1,2,3,4,5,6,7};//分别对应相应的数码管点亮

void delay(unsigned int cnt)

{

while(--cnt);

}

///

main()

{

unsigned char i;

while(1)

{

P0=dofly[i];//取显示数据

P2=seg[i]; //取段码

delay(200); //扫描间隙延时

i++;

if(8==i) //检测8位扫描完全?

i=0;

}

}

3.

/\/\

\ /

\/点阵C程序

#include

unsigned char const dofly[]={0x00,0x6C,0x92,0x82,0x44,0x28,0x10,0x00};// 心的形状

unsigned char code seg[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};//分别对应相应的段亮

void delay(unsigned int cnt)

{

while(--cnt);

}

///

main()

{

unsigned char i;

while(1)

{

P0=dofly[i];//取显示数据

P2=seg[i]; //取段码

delay(200); //扫描间隙延时

i++;

if(8==i)

i=0;

}

}

4.实时时钟RTC

#include

#include

sbit SCK=P3^6;

sbit SDA=P3^4;

sbit RST = P3^5; // DS1302复位

bit ReadRTC_Flag;

unsigned char l_tmpdate[7]={0,0,12,15,5,3,8};//秒分时日月周年08-05-15 12:00:00

unsigned char l_tmpdisplay[8];

code unsigned char write_rtc_address[7]={0x80,0x82,0x84,0x86,0x88,0x8a,0x8c}; //秒分时日月周年 最低位读写位

code unsigned char read_rtc_address[7]={0x81,0x83,0x85,0x87,0x89,0x8b,0x8d};

code unsigned char table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};

//共阴数码管 0-9 '-' '熄灭‘表

code unsigned char table1[]={0,1,2,3,4,5,6,7};

//显示位码表

void Write_Ds1302_byte(unsigned char temp);

void Write_Ds1302( unsigned char address,unsigned char dat );

unsigned char Read_Ds1302 ( unsigned

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值