******************************************************** *文件名:Password_clock
*功能:利用AT24c02,输入密码播放一段音乐,同时可以修改密码 *创建人:计算机科学与信息工程学院 米中勤 2011-9-5
*********************************************************/ #include
#define uint unsigned int #define uchar unsigned char
sbit lcd_rs=P2^5;//1602lcd数据/命令选择引脚 sbit lcd_rw=P2^6;//1602lcd读写引脚 sbit lcd_en=P2^7;//1602lcd使能端 sbit scl=P1^5; //24c08 SCL sbit sda=P3^6; //24c08 SDA sbit Int0=P3^2; //外部中断0 sbit In=P3^3;//输入密码键 sbit Ch=P3^4;//修改密码键 sbit d=P1^2;//蜂鸣器驱动引脚 uchar Count;
uchar m,tmp,lock_flag; static uint kai=0;
uchar code Seg_table[]=%uchar Enter[14]=%uchar init_password[6]=%uchar a[5]=\
uchar b[16]=\/*以下数组是音符编码*/
unsigned char code pu[282]={ 0x03,0xfb,0x05,0x00,0x00,0x04, 0x03,0xfb,0x02,0x03,0xfb,0x02, 0x43,0xfc,0x02,0x0b,0xfc,0x02, 0x8f,0xfb,0x02,0x8f,0xfb,0x02, 0x8f,0xfb,0x02,0x03,0xfb,0x02, 0x8f,0xfb,0x05,0x00,0x00,0x03, 0x43,0xfc,0x02,0x8f,0xfb,0x02, 0x43,0xfc,0x02,0x8f,0xfb,0x02, 0x43,0xfc,0x04,0x8f,0xfb,0x02, 0x03,0xfb,0x02,0x8f,0xfb,0x02, 0x03,0xfb,0x02,0x14,0xfa,0x02, 0x8f,0xfb,0x02,0x03,0xfb,0x05, 0x00,0x00,0x03,0x03,0xfb,0x05, 0x00,0x00,0x04,0x03,0xfb,0x02, 0x03,0xfb,0x02,0x43,0xfc,0x02,
0x0b,0xfc,0x02,0x8f,0xfb,0x02, 0x8f,0xfb,0x02,0x8f,0xfb,0x02, 0x03,0xfb,0x02,0x8f,0xfb,0x02, 0x00,0x00,0x03,0x43,0xfc,0x02, 0x8f,0xfb,0x02,0x43,0xfc,0x02, 0x8f,0xfb,0x02,0x43,0xfc,0x04, 0x8f,0xfb,0x02,0x03,0xfb,0x02, 0x8f,0xfb,0x02,0x03,0xfb,0x02, 0x8f,0xfb,0x02,0x08,0xfd,0x02, 0xab,0xfc,0x02,0x00,0x00,0x03, 0x08,0xfd,0x02,0xab,0xfc,0x02, 0x08,0xfd,0x02,0xab,0xfc,0x02, 0x08,0xfd,0x04,0xab,0xfc,0x02, 0x43,0xfc,0x02,0xab,0xfc,0x02, 0x43,0xfc,0x02,0x43,0xfc,0x04, 0x08,0xfd,0x04,0x03,0xfb,0x02, 0x8f,0xfb,0x02,0x08,0xfd,0x04, 0xab,0xfc,0x04,0xab,0xfc,0x02, 0x43,0xfc,0x02,0x43,0xfc,0x04, 0x43,0xfc,0x04,0x8f,0xfb,0x04, 0xab,0xfc,0x04,0x00,0x00,0x04, 0x08,0xfd,0x02,0xab,0xfc,0x02, 0x08,0xfd,0x02,0xab,0xfc,0x02, 0x08,0xfd,0x04,0xab,0xfc,0x02, 0x43,0xfc,0x02,0xab,0xfc,0x02, 0x43,0xfc,0x02,0x43,0xfc,0x02, 0x08,0xfd,0x04,0x03,0xfb,0x02, 0x8f,0xfb,0x02,0x08,0xfd,0x02, 0xab,0xfc,0x02,0xab,0xfc,0x05, 0x00,0x00,0x02,0x03,0xfb,0x02, 0x8f,0xfb,0x02,0xab,0xfc,0x04, 0x43,0xfc,0x02,0x43,0xfc,0x05 };
/******************************************************************* *名称:delay_music() *功能:音乐节拍延时
*输入:a a=1,1/16/拍,a=2,1/8拍,a=4,1/4拍 *输出:无
********************************************************************/ void delay_music(unsigned char a) {
unsigned int b; while(a--)
{
for(b=10300;b>=1;b--); } }
/******************************************************************** * 名称 : delay1() * 功能 : 短暂延时 * 输入 : x * 输出 : 无
***********************************************************************/ void delay1(uchar x) { uint i;
for(i=0; i /******************************************************************** * 名称 : Delay_1ms() * 功能 : 延时,延时时间为 1ms * i * 输入 : i(延时1ms的个数) * 输出 : 无 ***********************************************************************/ void Delay_1ms(uint i) { uchar x, j; for(j=0; j for(x=0; x<=148; x++); } /******************************************************************** * 名称 : Delay_xMs() * 功能 : 延时子程序,经过软件调试,测得延时程序大概为55us. * 输入 : x * 输出 : 无 ***********************************************************************/ void Delay_xMs(uint x) { uint i,j; for(i=0; i for(j=0; j<3; j++); } } /******************************************************************** * 名称 : flash() * 功能 : 延时,时间为2个NOP,大概为2US * 输入 : 无 * 输出 : 无 ***********************************************************************/ void flash(void) { _nop_(); _nop_(); } /******************************************** *名称:delay() *功能:延时大概140us *输入:无 *输出:无 *********************************************/ void delay() { int i,j; for(i=0; i<=10; i++) for(j=0; j<=2; j++); } /********************************************* *名称:lcd_writecom(uchar com) *功能:向1602写入命令 *输入:命令 *输出:无 **********************************************/ void lcd_writecom(uchar com) { lcd_rs=0; lcd_rw=0; lcd_en=0; P0=com; delay(); lcd_en=1; delay(); lcd_en=0; } /********************************************** *名称:lcd_readdata(uchar dat) *功能:向1602lcd写入数据 *输入:dat *输出:无 ***********************************************/ void lcd_writedata(uchar dat) { lcd_rs=1; lcd_rw=0; lcd_en=0; P0=dat; delay(); lcd_en=1; delay(); lcd_en=0; } /***************************************** *名称:lcd_init() *功能:1602lcd初始化 *输入:无 *输出:无 ******************************************/ void lcd_init() { lcd_writecom(0x38); lcd_writecom(0x0c); lcd_writecom(0x06); lcd_writecom(0x01); lcd_writecom(0x80); } /************************************************ *名称:lcd_char(uchar row ,uchar cloum,uchar dat) *功能:在lcd的第row行,第cloum列,写入数据dat *输入:row cloum dat *************************************************/ void lcd_char(uchar row ,uchar cloum,uchar dat) { if(row==1) { lcd_writecom(0x80+cloum); lcd_writedata(dat); } else { lcd_writecom(0x80+0x40+cloum); lcd_writedata(dat); } } /********************************************* 百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库电子密码锁程序在线全文阅读。
相关推荐: