收藏 分销(赏)

一个简单的密码开锁程序.doc

上传人:pc****0 文档编号:7844804 上传时间:2025-01-20 格式:DOC 页数:8 大小:30KB
下载 相关 举报
一个简单的密码开锁程序.doc_第1页
第1页 / 共8页
一个简单的密码开锁程序.doc_第2页
第2页 / 共8页
一个简单的密码开锁程序.doc_第3页
第3页 / 共8页
一个简单的密码开锁程序.doc_第4页
第4页 / 共8页
一个简单的密码开锁程序.doc_第5页
第5页 / 共8页
点击查看更多>>
资源描述

1、一个简单的密码开锁程序/-/ File: main.c/ Contents;/ uP control Process/ / Copyright (c) 2006 * CO LTD. All rights reserved./ from: / $Date: 11/10/2006/ $Revision: 1011/-i nclude /-/ Random Macros/-#define min(a,b) (a)(b)?(a):(b)/-/ Constants/-char code Revsion = n uP control Processn Revision:1.0n Data:2006/9/2

2、0n Copyright(c)2006 Wincotime CO LTD. All rights reservedn;int code TABLE132 = D,0x10, 1,0x20, 2,0x40, 3,0x80, 4,0x30, 5,0x50, 6,0x90, 7,0x60, 8,0xA0, 9,0xC0, 0,0xD0, *,0x70, #,0xB0 ; #define CON_SW1 P3_7#define CON_SW2 P3_5#define CON_SW3 P3_4#define CON_SW4 P3_0#define CON_LOCK P3_1/-/ Global Vari

3、ables/-unsigned char csSWH;unsigned char csSWL;unsigned char ccCode;unsigned char cKeyCounter;unsigned long ulKeySampleTime;unsigned long ulOpenLockTime;char cKeyA;char cKeyReg4;char cPSW4;bit bsKeyOk;bit bsLock;bit bsT1ms;/-/ Prototypes/-void TD_Init (void);void TD_InitINT0 (void);void TD_InitTMR0

4、(void);void TD_ProcdutTest(void);void TD_SWSample (void);bit TD_PSWCheck (void);void Delay1ms (void);/-/ Code/-main () TD_Init(); /TD_ProcdutTest(); while(1) / Switch Sample TD_SWSample (); / Lock Control if(TD_PSWCheck () CON_LOCK = 1; ulOpenLockTime = 0; while(ulOpenLockTime10000) else CON_LOCK =

5、0; / End of Main Function/-/ Task Dispatcher hooks/ The following hooks are called by the task dispatcher./-void TD_Init(void) unsigned char i; CON_SW1 = CON_SW2 = CON_SW3 = CON_SW4 = 0; ulKeySampleTime = 0; bsKeyOk = 0; cKeyCounter = 0; for(i=0;i4;i+)cKeyRegi = 0; TD_InitINT0(); TD_InitTMR0();void

6、TD_InitINT0 (void) IT0 = 1; / Configure interrupt 0 for falling edge on /INT0 (P3.2) EX0 = 1; / Enable EX0 Interrupt EA = 1; / Enable Global Interrupt Flagvoid TD_InitTMR0 (void) TH0 = 255 - 200; TMOD = (TMOD & 0xF0) | 0x02; /* Set T/C0 Mode */ ET0 = 1; /* Enable Timer 0 Interrupts */ TR0 = 1; /* St

7、art Timer 0 Running */ EA = 1; /* Global Interrupt Enable */*void TD_ProductTest(void)*/void TD_SWSample(void) unsigned char temp; CON_SW1 = 1; Delay1ms(); temp = P1&0xF; if(temp10)cPSW0=temp+0x30; CON_SW1 = 0; CON_SW2 = 1; Delay1ms(); temp = P1&0xF; if(temp10)cPSW1=temp+0x30; CON_SW2 = 0; CON_SW3 =

8、 1; Delay1ms(); temp = P1&0xF; if(temp10) cPSW2=temp+0x30; CON_SW3 = 0; CON_SW4 = 1; Delay1ms(); temp = P1&0xF; if(temp10)cPSW3=temp+0x30; CON_SW4 = 0;void Delay1ms () bsT1ms = 1; if(bsT1ms) bsT1ms = 1; if(bsT1ms) bsT1ms = 1; if(bsT1ms) bsT1ms = 1; if(bsT1ms) bsT1ms = 1; if(bsT1ms) bsT1ms = 1; if(bs

9、T1ms)bit TD_PSWCheck (void) unsigned char i; bit btemp; if(bsKeyOk) bsKeyOk = 0; cKeyCounter = 0; for(i=0;i4;i+) if(cKeyRegi!=cPSWi) btemp = 0; return 0; else btemp = 1; if(btemp)return 1; else return 0;/-/ MCS51 Interrupt Handlers/ The following functions are called by 51 interrupt jump vector table/-void ISR_INT0 (void) interrupt IE0_VECTOR unsigned char i; ulKeySampleTime = 0; ccCode = 0; ccCode = P1&0xF0; for(i=0;i=4) bsKeyOk = 1; cKeyCounter=0; break; default: if(cKeyCounter150000) / 1s ulKeySampleTime = 0; bsKeyOk = 0; cKeyCounter = 0; for(i=0;i4;i+)cKeyRegi=0; bsT1ms = 0;

展开阅读全文
部分上传会员的收益排行 01、路***(¥15400+),02、曲****(¥15300+),
03、wei****016(¥13200+),04、大***流(¥12600+),
05、Fis****915(¥4200+),06、h****i(¥4100+),
07、Q**(¥3400+),08、自******点(¥2400+),
09、h*****x(¥1400+),10、c****e(¥1100+),
11、be*****ha(¥800+),12、13********8(¥800+)。
相似文档                                   自信AI助手自信AI助手
搜索标签

当前位置:首页 > 百科休闲 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服