資源簡介
利用STC89C52控制繞線機,可以正轉、反轉并顯示繞線的圈數
代碼片段和文件信息
// 2016-7-15
//======================用int0中斷處理計數,每中斷一次,根據轉動方向增加或減少顯示實際匝數1匝=================
//?***********?驅動8位數碼管?*************?
#include?
#include?
#define?uchar?unsigned?char??
????unsigned?char?table1[]={0x3F0x3F0x3F0x3F0x3F0x3F0x3F0x3F};????????//1-8的字模
????unsigned?char?table2[]={0x7F0xbF0xdF0xeF0xf70xFb0xFd0xFe};??????????//選通碼??
????unsigned?char?table[]={0x3F?0x06?0x5B?0x4F?0x66?0x6D?0x7D?0x07?0x7F?0x6F};???//0-9的字模???????
????sbit??start=P3^0;
????sbit??forward=P3^1;
????sbit??back=P3^1;
????sbit??thousand_up=P1^0;
????sbit??hundred_up=P1^1;
????sbit??decade_up=P1^2;
????sbit??unit_up=P1^3;
????sbit??thousand_down=P1^4;
????sbit??hundred_down=P1^5;
????sbit??decade_down=P1^6;
????sbit??unit_down=P1^7;
????sbit??beep=P3^7;
????
void?delay(unsigned?int?i) ?//延時程序
????{
???????unsigned?int?j;
???????unsigned?char?k;
???????for(j=i;j>0;j--)
??????????for(k=125;k>0;k--);
????}
void?previous(unsigned?int?i) //把當前數的字模調整為比它小1的數的字模
???{
?????unsigned?int?j;
?????for(j=0;j<10;j++)
????????{
??????????if(table[j]==table1[i])
?????????????{
????????????????if(j==0)
???????????????????{
???????????????????????table1[i]=0x6f;
????????????????????}
?????????????????else
????????????????????{
???????????????????????table1[i]=table[j-1];
?????????????????????}
?????????????????return?;???????????????????????????????????????????????????????????????????
???????????????}
??????????}
?????}
??????????
void?next(unsigned?int?i) ??????//把當前數的字模調整為比它大1的數的字模
????{
??????unsigned?int?j;
??????for(j=0;j<10;j++)
?????????{
???????????if?(table[j]==table1[i])
??????????????{
?????????????????if(j==9)
????????????????????{
???????????????????????table1[i]=0x3f;
?????????????????????}
?????????????????else
????????????????????{
???????????????????????table1[i]=table[j+1];
?????????????????????}
?????????????????return?;????????????????????????????????????????????????????????
???????????????}
??????????}
????}
void??real_num_up(??????????) ??//增加當前計數器顯示的數字
???{
?????if?(table1[7]==?0x6f)
????????{
???????????table1[7]=0x3f;
???????????if?(table1[6]==?0x6f)
??????????????{
?????????????????table1[6]=0x3f;
?????????????????if?(table1[5]==?0x6f)
????????????????????{
???????????????????????table1[5]=0x3f;
???????????????????????if?(table1[4]==?0x6f)
??????????????????????????{
?????????????????????????????table1[4]=0x3f;
???????????????????????????}
???????????????????????else
??????????????????????????{
?????????????????????????????next(4);
???????????????????????????}
?????????????????????}
??????????????????else
????????????????????{
???????????????????????next(5);
?????????????????????}
???????????????}
????????????else
??????????????{
??????????????????next(6);
???????????????}
?????????}
??????else
?????????{
????????????next(7);
??????????}
?????}
?void??real_num_down() ?//減小當前計數器顯示的數字
????{
??
- 上一篇:花草信息管理系統.c
- 下一篇:C++商店收銀系統(控制臺)
評論
共有 條評論