/*
短按兩下按鈕暫停上數,再按一下按鈕繼續計數(按一下不做任何動作) 5% 7. 長按按鈕計數歸零 10%
*/
#include "REG51.h"
int i=20;
int j=0;
int q;
int x=1;
int press_add=0;
sbit sw1=P3^2;
sbit sw2=P3^3;//短按兩下
char count=0;
char bcd[2]={0,0};
static const char P1table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
static const char P2table[]={1,2};
void delay_1ms(int k)
{
int i,j;
for(i=0;i<k;i++)
for(j=0;j<110;j++)
;
}
void mode()
{
P1=P1table[0];P2=~P2table[0];
P1=P1table[0];P2=~P2table[1];
}
void main()
{
IE=0x8a;
TMOD=0x10;
TH0=(8192-5000)/32;
TL0=(8192-5000)%32;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
TR0=0;
TR1=0;
while(1)
{
for(q=0;q<50;q++)
{
if(x==1) mode();
if(sw1==0)
{
x=0;
TR0=1;TR1=1;
}
if(sw2==0)
{
press_add++;
delay_1ms(20);while(sw2==0);delay_1ms(20);
if(press_add==2)
{
TR0=1;TR1=0;
}
if(press_add==3)
{
press_add=0;
TR1=1;
}
}
}
}
} /* main */
void T0_int(void) interrupt 1
{
TH0=(8192-5000)/32;
TL0=(8192-5000)%32;
P1=P1table[ bcd[j] ];
P2=~P2table[j];
j++;
if(j==2)
j=0;
}
void T1_int(void) interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
i = i-1;
if(i==0)
{
i=20;
count++;
if(count==100)
count=0;
bcd[1]=count/10;
bcd[0]=count%10;
}
}
訂閱:
張貼留言 (Atom)
algorithm
#include <iostream> #include <string.h> using namespace std; int main(int argc, char** argv) { for(int j=2;j<=100;j++)//j...
-
本文旨在補充《 超圖解Arduino互動設計入門 》第18章「RFID無線識別裝置與問答遊戲製作」單元,書本採用的RFID讀卡機模組是採用9600bps, TTL序列通訊介面,RFID的通訊頻率為125KHz。這種模組的接線和程式都很簡單,每當感測到RFID卡,讀卡機就把...
-
3.Keil C 幫我們寫好 程式:#include <reg51.h> vs c語言 #include <stdio.h> //幫您宣告 P0=0x80 有相對的記憶體以十六進位表示,它定義定reg51.h,我們直接拿來用他的代碼即可 P1=0...
-
/* 多重按鈕開關 */ //==宣告區================================ #include // 定義8051暫存器之標頭檔,P2-17~19 #include "myio.h" // 自己寫的I/O程式庫 sbit PB...
沒有留言:
張貼留言