标题:
AVR单片机pwm程序+仿真_数显
[打印本页]
作者:
jinsheng7533967
时间:
2018-12-16 16:09
标题:
AVR单片机pwm程序+仿真_数显
oooooooooooo.jpg
(126.86 KB, 下载次数: 87)
下载附件
2018-12-16 16:06 上传
#include <iom16v.h>
#define uchar unsigned char
#define uint unsigned int
uchar Table[12]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x79};
uchar Data1[4]={10,0,5,0};
uchar Data2[4]={3,9,1,0};
uchar Key1,Key2;
void DelayMs(uchar i)
{
uchar j;
for(;i!=0;i--)
{
for(j=150;j!=0;j--);
}
}
void Display(uchar *p)
{
uchar i,sel=0x01;
for(i=0;i<4;i++)
{
PORTC=sel;
PORTA=0xff-Table[p[i]];
DelayMs(2);
sel=sel<<1;
}
}
void Sub_Process(uchar *p)
{
uchar temp;
temp=p[1]*10+p[2];
if(temp!=0)
{
temp=temp-1;
p[1]=temp/10;
p[2]=temp%10;
}
}
void Key_Process()
{
if(Key1==1)
{
Add_Process(Data1);
Key1=0;
}
if(Key2==1)
{
Sub_Process(Data1);
Key2=0;
}
}
void Init_IO(void)
{
DDRA=0xff;
PORTA=0xff;
DDRC=0xff;
PORTC=0xff;
DDRB=0x00;
PORTB=0x00;
DDRD=0xff;
PORTD=0xff;
}
void main(void)
{
Init_IO();
TCCR1A=0xc3;
TCCR1B=0x02;
DelayMs(50);
while(1)
{
Key_Process();
Set_Process(Data1);
Display(Data1);
}
}
复制代码
完整代码见附件
pwm_数显.zip
(15.36 KB, 下载次数: 52)
2018-12-16 16:09 上传
点击文件名下载附件
下载积分: 黑币 -5
作者:
zrb5688
时间:
2018-12-26 17:52
不错,学习了,谢谢楼主分享。
作者:
dhutcb
时间:
2019-5-30 10:20
赞一个,不错
作者:
yaolong986
时间:
2020-11-24 15:36
不错,收藏了有用这芯片
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1