欢迎来到天天文库
浏览记录
ID:42496590
大小:311.48 KB
页数:10页
时间:2019-09-16
《IC卡智能煤气控制系统》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、附录1:主控单元原图vccVCCPIfengR5lkP12vccTCLKJcRST_icic_kIOJcWORKERROR+12VL2LM2576HVI-5.0LB03INIBON/OFFOUTGNDInductorlOOuHDIHeader8klk2k3k4SIS2S3S4VCCP4VCCLSI1//2NQI▲2N39O4330uF/50V1N4007•e►—30uF/50VVCCR610kCLKJ&RSTic3,IO」c5_MOShVORK6M1SCERROR7SCK8.RESETC514aRE
2、SET9□YlC8II.0592M22pJPI1213VCCl叫A」RP2IKPBO(XCK/TO)PB1(Tl)PB2(AIN0/INT2)P? (ADCO)P?l(ADC1)PA23、(TMS)PD4(OCIB)PC4(TDO)PD5(OC1A)PC5(TDI)PD6(ICP)PC6(TOSCI)PD7(OC2)PC7(TOSC2)vccRESETAVCCAREFXTAL2XTAL1GNDGNDU432/Tn«gal6-16PI40RW39RSE37kl互k3k4厂>an()lTVCCC6IfMC7104inl2P2T14+12V4、2536Header3X2AP3inl2Header附录2:源程序#ifndefAT_H_〃名字里不能冇中文#defineAT_H_#defineu5、charunsignedchar#defineuintunsignedint#definesda_INDDRB&=〜BIT(4)/*设置输入*/#definesda_OUTDDRB1=BIT(4)/*设這输出*/#definesda_LPORTB&二〜BIT(4)/*置低电平*/#definesda_HPORTBI=BIT(4)/*置高电平*/#definesda_read(PINB&0xl())>>4/*读了电平*/#defineclk_LPORTB&二~BIT(1)/*置低电平*/#define6、clk_HPORTBl=BIT(l)/*置高电平*/#defineIC_ENT(PINB&()x()8)==()X()()〃插入IC卡#defineERROR_0PORTB1=BIT(5)〃错误灯熄灭#defineERROR.1PORTB&=~B1T(5)〃插卡错谋灯点亮#defineWORK_0PORTB1=BIT(6)〃工作灯熄灭#defineWORK_1PORTB&二〜BIT(6)〃止常工作灯点亮#defineEETYPEAT24C02#defineAT24C01127#defineAT24C7、02255#defineAT24C04#defineAT24C08#defineAT24C16#defineAT24C32#defineAT24C645111023204740958191#defineAT24C12816383#defineAT24C25632767//24CXX驱动函数(适合24C01〜24C16,24C32〜256未经过测试!有待验证!)〃止点原子@ALIENTEK〃产生IIC起始信号voidIIC_Start(void){sda_OUT;〃sda线输岀clk_H;sda_H;8、delay_us(4);sda_L;//START:whenCLKishigh,DATAchangeformhightolowdelay_us(4);clk_L;〃钳住I2C总线,准备发送或接收数据)〃产牛IIC停止信号voidIIC_Stop(void){sda_OUT;//sda线输出clk_L;sda_L;//STOP:whenCLKishighDATAchangeformlowtohighdelay_us(4);clk_H;sda_H;delay_us(4);}〃等待应答信号到來〃返冋值:19、,接收应答失败//0,接收应答成功ucharIIC_Wait_Ack(void)uintucErrTime=O;sda_IN;//SDA设置为输入sda_H;delay_us(l);clk_H;delay_us(l);while(sda_read){ucErrTime++;if(ucErrTime>250){IlC.StopO;return1;1}clk.L;//时钟输出0return0:}〃产生ACK应答在笫九个脉冲期间,当sdn为高电平时,产生ACK应答信号voi
3、(TMS)PD4(OCIB)PC4(TDO)PD5(OC1A)PC5(TDI)PD6(ICP)PC6(TOSCI)PD7(OC2)PC7(TOSC2)vccRESETAVCCAREFXTAL2XTAL1GNDGNDU432/Tn«gal6-16PI40RW39RSE37kl互k3k4厂>an()lTVCCC6IfMC7104inl2P2T14+12V
4、2536Header3X2AP3inl2Header附录2:源程序#ifndefAT_H_〃名字里不能冇中文#defineAT_H_#defineu
5、charunsignedchar#defineuintunsignedint#definesda_INDDRB&=〜BIT(4)/*设置输入*/#definesda_OUTDDRB1=BIT(4)/*设這输出*/#definesda_LPORTB&二〜BIT(4)/*置低电平*/#definesda_HPORTBI=BIT(4)/*置高电平*/#definesda_read(PINB&0xl())>>4/*读了电平*/#defineclk_LPORTB&二~BIT(1)/*置低电平*/#define
6、clk_HPORTBl=BIT(l)/*置高电平*/#defineIC_ENT(PINB&()x()8)==()X()()〃插入IC卡#defineERROR_0PORTB1=BIT(5)〃错误灯熄灭#defineERROR.1PORTB&=~B1T(5)〃插卡错谋灯点亮#defineWORK_0PORTB1=BIT(6)〃工作灯熄灭#defineWORK_1PORTB&二〜BIT(6)〃止常工作灯点亮#defineEETYPEAT24C02#defineAT24C01127#defineAT24C
7、02255#defineAT24C04#defineAT24C08#defineAT24C16#defineAT24C32#defineAT24C645111023204740958191#defineAT24C12816383#defineAT24C25632767//24CXX驱动函数(适合24C01〜24C16,24C32〜256未经过测试!有待验证!)〃止点原子@ALIENTEK〃产生IIC起始信号voidIIC_Start(void){sda_OUT;〃sda线输岀clk_H;sda_H;
8、delay_us(4);sda_L;//START:whenCLKishigh,DATAchangeformhightolowdelay_us(4);clk_L;〃钳住I2C总线,准备发送或接收数据)〃产牛IIC停止信号voidIIC_Stop(void){sda_OUT;//sda线输出clk_L;sda_L;//STOP:whenCLKishighDATAchangeformlowtohighdelay_us(4);clk_H;sda_H;delay_us(4);}〃等待应答信号到來〃返冋值:1
9、,接收应答失败//0,接收应答成功ucharIIC_Wait_Ack(void)uintucErrTime=O;sda_IN;//SDA设置为输入sda_H;delay_us(l);clk_H;delay_us(l);while(sda_read){ucErrTime++;if(ucErrTime>250){IlC.StopO;return1;1}clk.L;//时钟输出0return0:}〃产生ACK应答在笫九个脉冲期间,当sdn为高电平时,产生ACK应答信号voi
此文档下载收益归作者所有