Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 6656|回復: 1
打印 上一主題 下一主題

Scanning 7-Segment & Keypad-(89c2051)

[複製鏈接]
跳轉到指定樓層
1#
發表於 2006-8-16 13:41:41 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
[size=+3]掃瞄7-鍵盤部分& [size=+1]WichitSirichote, Kswichit@kmitl.ac.th
[size=+1]由於產量的緩衝P1可以匯20ma(每生產針,但是所有產出最高IOL僅限於80ma),從而可以利用P1駕駛直接領導展示. 所示電路,兩個共同陽極七連部分圍繞當前P1與180ohms電阻限制. 各部門領導都與兩個平行P1. 第一和第二季的邏輯,是啟動和P3.1P3.0低、來源五五陽極共同別針. 如果不是經過邏輯P3.4低年級、中一緊,取得了掃瞄時間.
  
[size=+3]7SEG.C
[size=+1]7SEG.C
[size=+1]7SEG.HEX
[size=+1]簡單計算表明了節目結束. S1是用來設定時間99點開始的課下來.
/*
-7-SEG.C
*駕駛2位數7部門共同領導科學陽極鍵盤
*版權(C)1999WichitSirichote
Dunfield*編輯與微觀C釋放3208051
*C:\麥當勞\cc517-SEG-石=C:\TM=司儀
*/
#:C:\麥當勞\8051io.h/包括我*/*澳頭檔案/
#:C:\麥當勞\8051reg.h
extern鼐Cputick登記; //Cputickincremented是每10ms
flag1鼐簽名登記;
簽名冊SEC鼐、數字、緩衝2.
註冊燒焦關鍵;
鼐將10=0X3F法國,0X0C,0X76,0x5E,0x4D,0x5B,0x7B,0X0E,0x7F,0x5f];
  
/*使我國的部分指定針(不同於標準)
B
__
一立__選C
F代代丁
   --
e
*/
#確定setValue99
主要()
{
flag1=0;
SEC=setValue;
Timetobuffer();
Serinit(9600); //要定16有點反timer0
(1)在法國
而(CPUTICK"10)
scanled();
//每100ms執行下列職務
Cputick=0;
Timetobuffer();
Keyexe();
公園();
                  }
}
  
scanled()/掃瞄*2位數和2導致鑰匙開關,主要關鍵壓力=0-1
其他重要=-1*/
{
我Int.
數字=0x02; //掃瞄代碼00000010
=-1關鍵;
為(0=我; 我"2. 我++)/*2*數字掃瞄/
    {
~P3=數字; /**送補充[數字]/
P1=~[I]緩衝; /*發送補充[部分]*/
拖延(1); /**延遲1MS/
P1=0xff; /**產領導/
如果((P3&0X10)==0)/*如果是關鍵P3.4低壓*/
=關鍵一; /**救關鍵地位的關鍵因素/
數字""=1; /**未來數字/
    }
}
Timetobuffer()//SEC數據轉換為二元七部分格局
{
緩衝轉換[0]=[SEC10%〕;
1=轉換緩衝[sec/10〕;
}
公園()
{
如果((0X02FLAG1&)! =0)
SEC--;
如果(SEC4-0)
~&FLAG1=0x02; //比較明顯違反
}
Keyexe()
{
如果(重要! =-1)
    {
開關(鑰匙)法國
案例(0):/**0關鍵位置/
重新(); /0**關鍵處/
打破;
案例(一):/*1*重要地位/
經營(); /**1主要服務/
                }
    }
}
重新()
{
SEC=setValue; //重新定值
Timetobuffer();
~&FLAG1=0x02; //停止下來票
}
經營()
{
如果(SEC! =0)
flag1選=0x02; //開始計算下跌
}

[size=+3]演習

  • [size=+1]公園()功能或減薪的可能性時每100ms0.1sec,嘗試改變SEC1.
  • [size=+1]利用探測器檢查P3.7邏輯,觀察是否有脈搏. 使用這種晶體管小別針連接,帶動了鐘聲,鐘聲修改源計劃啟動計值為零時.
  • [size=+1]見 時鐘控制 為詳細數字掃瞄四、圍繞四個重點掣.
[size=+2]"內容 | 終點站 > [size=+0]最後更新,2542年11月4日
2#
 樓主| 發表於 2006-8-16 13:43:12 | 只看該作者
http://chaokhun.kmitl.ac.th/~kswichit/2051/7-seg/7-seg.htm
[size=+1]7-SEG.C
[size=+1]7-SEG.HEX
[size=+1]The program demonstrates simple counting down clock. S1 is used for setting time to 99, S2 for start count down.
/*
* 7-seg.c
* Driving 2-digit 7-segment Common Anode LED & keypad
* Copyright (C) 1999 Wichit Sirichote
* compiled with Dunfield Micro-C for 8051 Release 3.2
* c:\mc\cc51 7-seg -i h=c:\mc m=t
*/
#include c:\mc\8051io.h  /* include i/o header file */
#include c:\mc\8051reg.h
extern register char cputick; // cputick was incremented every 10ms
register unsigned char flag1;
unsigned register char sec,digit,buffer[2];
register char key;
char convert[10] = {0x3F,0x0c,0x76,0x5e,0x4d,0x5b,0x7b,0x0e,0x7f,0x5f};
  
/*  my LED's segment pin designation (differs from standard)
   b
   __
a|__| c
f|  | d
   --
   e
*/
#define setValue 99
main()
{
          flag1 = 0;
          sec = setValue;
          timeToBuffer();
          serinit(9600); // set timer0 to be 16 bit counter
          while(1){
               while(cputick < 10)
                scanLED();
            // execute the following functions every 100ms
                cputick = 0;
                timeToBuffer();
                keyexe();
                countdown();
                  }
}
  
scanLED() /* scan 2-digit LED and 2-key switch, if key pressed key = 0-1
else key = -1 */
{
    int i;
    digit = 0x02;    // scan code 00000010
    key = -1;
    for( i = 0; i < 2; i++)  /* 2-DIGIT scanning */
    {
        P3 = ~digit;      /* send complement[digit] */
        P1 = ~buffer;  /* send complement[segment] */
        delay(1);         /* delay 1ms */
        P1 = 0xff;        /* off LED */
        if ((P3 & 0x10) == 0) /* if key pressed P3.4 became low */
           key = i;       /* save key position to key variable */
        digit>>=1;        /* next digit */
    }
}
timeToBuffer() // converts binary data in sec to 7-segment pattern
{
    buffer[0] = convert[sec%10];
    buffer[1] = convert[sec/10];
}
countdown()
{
    if ((flag1 & 0x02) != 0)
        sec--;
        if (sec == 0 )
                flag1 &= ~0x02;  // clear run bit
}
keyexe()
{
    if (key != -1)
    {
      switch(key){
        case (0): /* key position 0 */
        reset();  /* service key 0 */
        break;
        case (1): /* key position 1 */
        run();    /* service key 1 */
                }
    }
}
reset()
{
        sec = setValue;  // reload set value
        timeToBuffer();
        flag1 &= ~0x02;  // stop counting down
}
run()
{
        if (sec != 0)
        flag1 |= 0x02; // start counting down
}
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-5-21 05:28 , Processed in 0.119091 second(s), 7 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表