资源简介
用于mega16控制的直流电机小车测速、计路程。用于计数光电传感器的输入脉冲,实现测速和测距离。
代码片段和文件信息
#include
#include
#define clr_595_1 PORTB|= (1<<6)
#define clr_595_0 PORTB&=~(1<<6)
#define clk_595_1 PORTB|= (1<<7)
#define clk_595_0 PORTB&=~(1<<7)
#define cp_595_1 PORTB|= (1<<4)
#define cp_595_0 PORTB&=~(1<<4)
#define di_595_1 PORTB|= (1<<5)
#define di_595_0 PORTB&=~(1<<5)
flash unsigned char disp[]={0x3F0x060x5B0x4F0x660x6D0x7D0x070x7F0x6F0x770x7C0x390x5E0x790x710x00};
unsigned char position[]={0000};
unsigned char posit=0;
unsigned int counter=0;
unsigned char state=0;
int n=0;
void show_595(unsigned char c)/////////595显示
{
int wx;
unsigned char num;
clr_595_1;
num=disp[c]; //num表示c对应的段码
for(w=0;w<8;w++)
{
clk_595_0;
x=num&0x80; //取段码最高位
if(x==0)
{
di_595_0; //打入0
}
else
{
di_595_1;
}
delay_us(2)
评论
共有 条评论