|
- ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
- ;原理:通过改变加热管通电和断电时间比达到控制温度作用。
- ;可以独立设置21路加热管通断的百分比值。
- ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
- ;设置参数方法:同时按下主机面板上的“区域”和“上调”(或“下调”)键,
- ;调到需要设定参数的区域后,停止按按键,然后再同时按下“参数”和“上调”(或“下调”)键,
- ;设定该区域的参数,参数设定范围0~100%,当设定参数为0%时关闭加热管,
- ;当设定参数为100%时加热管常通电,当设定参数为50%时加热管通断时间比为1:1(即各50%),
- ;其他参数以此类推。
- ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
- SC01# EQU P0.0 ;1#输出
- SC02# EQU P0.1 ;2#输出,以下雷同,共24路输出
- SC03# EQU P0.2
- SC04# EQU P0.3
- SC05# EQU P0.4
- SC06# EQU P0.5
- SC07# EQU P0.6
- SC08# EQU P0.7
- SC09# EQU P1.0
- SC10# EQU P1.1
- SC11# EQU P1.2
- SC12# EQU P1.3
- SC13# EQU P1.4
- SC14# EQU P1.5
- SC15# EQU P1.6
- SC16# EQU P1.7
- SC17# EQU P2.0
- SC18# EQU P2.1
- SC19# EQU P2.2
- SC20# EQU P2.3
- SC21# EQU P2.4
- SC22# EQU P2.5
- SC23# EQU P2.6
- SC24# EQU P2.7
- XS1A2 EQU P3.0 ;RXD,P3.0接74LS164 1A2端,用于显示,不能改变
- XSCLK EQU P3.1 ;TXD,P3.1接74LS164 CLK端,用于显示,不能改变
- AJQUY EQU P3.2 ;设置区域的按键,要同时按下区域键和上调或下调键方可调节
- AJCSH EQU P3.3 ;设置参数的按键,要同时按下参数键和上调或下调键方可调节
- AJSHT EQU P3.4 ;上调按键
- AJXIT EQU P3.5 ;下调按键
- SDA EQU P3.6 ;EEPROM数据传送口,必须接上拉电阻,否则有时开机不正常
- SCL EQU P3.7 ;EEPROM时钟传送口,必须接上拉电阻,否则有时开机不正常
- KMWDT EQU 0E1H ;看门狗地址
- ORG 0000H ;程序执行开始地址
- LJMP KS ;跳至KS
- ORG 0003H ;外中断0中断程序入口
- RETI ;跳至INT_0中断服务程序
- ORG 000BH ;定时器T0中断程序入口
- LJMP INTT0 ;中断返回
- ORG 0013H ;外中断1中断入口
- RETI ;中断返回
- ORG 001BH ;定时器T1中断程序入口
- RETI ;跳至INTT1中断服务程序
- ORG 0023H ;串口中断入口地址
- RETI
- ORG 0200H
- ;------------------------------------
- ;开机初始化
- ;------------------------------------
- KS: MOV KMWDT,#00111100B ;设置看门狗
- MOV R0,#0FFH ;延时,待电源正常后系统才开始工作
- DJNZ R0,$
- MOV P0,#0FFH
- MOV P1,#0FFH
- MOV P2,#0FFH
- MOV P3,#0FFH
- MOV SP,#70H
- MOV TMOD,#01H ;设置T0为16位定时器,方式1
- MOV TH0,#0D8H ;设定T0的定时初值,12M晶振,定时为10ms,
- MOV TL0,#0F0H ;通断总时间周期=10ms×100(因为分成100%)=1s
- SETB ET0 ;允许T0中断
- SETB EA ;开中断
- MOV 6FH,#00H ;6FH为10mS时间到标志,现置零
- ;开始运行,调用存储器保存的数据
- ;------------------------------------
- LCALL READ_DATA ;将EEPROM中原里程数据调入内存
- ;------------------------------------
- MOV 48H,#1 ;设定开机后显示屏显示1#区域的参数
- LCALL LEDXS1 ;调用显示程序
- ;------------------------------------
- ;把各区域内的参数值提取用于控制和显示
- MOV 50H,30H ;50H为1#输出时间参数值缓存区
- MOV 51H,31H ;51H为2#输出时间参数值缓存区
- MOV 52H,32H ;以下以此类推
- MOV 53H,33H
- MOV 54H,34H
- MOV 55H,35H
- MOV 56H,36H
- MOV 57H,37H
- MOV 58H,38H
- MOV 59H,39H
- MOV 5AH,3AH
- MOV 5BH,3BH
- MOV 5CH,3CH
- MOV 5DH,3DH
- MOV 5EH,3EH
- MOV 5FH,3FH
- MOV 60H,40H
- MOV 61H,41H
- MOV 62H,42H
- MOV 63H,43H
- MOV 64H,44H
- MOV 65H,45H
- MOV 66H,46H
- MOV 67H,47H
- ;------------------------------------
- ;各输出运行状态标志置零
- CLR 01H ;01H为1#输出运行状态标志(区分输出是高电平还是低电平)
- CLR 02H ;02H为2#输出运行状态标志(区分输出是高电平还是低电平)
- CLR 03H ;以下以此类推
- CLR 04H
- CLR 05H
- CLR 06H
- CLR 07H
- CLR 08H
- CLR 09H
- CLR 0AH
- CLR 0BH
- CLR 0CH
- CLR 0DH
- CLR 0EH
- CLR 0FH
- CLR 10H
- CLR 11H
- CLR 12H
- CLR 13H
- CLR 14H
- CLR 15H
- CLR 16H
- CLR 17H
- CLR 18H
- SETB TR0 ;启动T0
- ;------------------------------------
- ;按键处理程序
- ;------------------------------------
- L1: JB AJQUY,L5 ;设置区域值
- MOV P0,#0FFH ;设置区域时关闭所有输出口
- MOV P1,#0FFH
- MOV P2,#0FFH
- JB AJSHT,L3 ;上调区域,此时同时显示该区域的参数
- MOV A,48H
- CJNE A,#24,L2 ;检查调节区域值是否到达24区
- SJMP L0 ;到达24区的停止
- L2: INC 48H ;调节区域值步进加1
- SJMP L0
- L3: JB AJXIT,L1 ;下调区域,此时同时显示该区域的参数
- MOV A,48H
- CJNE A,#1,L4 ;检查调节区域值是否到达1区
- SJMP L0 ;到达1区的停止
- L4: DEC 48H ;调节区域值步进减1
- L0: MOV A,#2FH ;30H起开始放参数值,1区对应30H,2区对应31H,其他雷同
- ADD A,48H ;48H放当前区域值
- MOV R1,0E0H ;0E0H即为A的地址
- MOV 49H,@R1 ;49H放当前区域的参数值
- LCALL LEDXS1 ;调用显示子程序
- LCALL YS1 ;延时
- SJMP L1 ;返回再执行
- ;_____________________________________
- L5: JB AJCSH,L00 ;设置参数值
- MOV P0,#0FFH ;设置区域时关闭所有输出口
- MOV P1,#0FFH
- MOV P2,#0FFH
- MOV A,#2FH ;30H起开始放参数值,因为以下要加1,所以从2FH开始
- ADD A,48H
- MOV R1,0E0H ;0E0H即为A的地址
- MOV 49H,@R1
- JB AJSHT,L7 ;上调参数
- MOV A,49H
- CJNE A,#100,L6 ;参数等于100%不能再调
- SJMP L0
- L6: INC 49H ;参数调节步进加1
- SJMP L9
- L7: JB AJXIT,L1 ;下调参数
- MOV A,49H
- CJNE A,#0,L8 ;参数等于0%不能再调
- SJMP L0
- L8: DEC 49H ;参数调节步进减1
- L9: MOV @R1,49H
- LCALL LEDXS1 ;调用显示子程序
- LCALL WRITE_DATA ;把参数值数据存入EEPROM,防止掉电数据丢失
- LCALL YS1 ;延时
- SJMP L1 ;返回再执行
-
- ;------------------------------------
- ;输出
- ;------------------------------------
- L00: MOV A,30H ;检查1#参数是否为0%
- JNZ L01 ;1#参数不为0%时继续检测
- SETB SC01# ;1#参数为0%时关闭1#输出
- SJMP L10 ;关闭1#输出后转检测2#端口
- L01: CJNE A,#100,L02 ;检查1#参数是否为100%
- CLR SC01# ;1#参数为100%时1#有输出
- SJMP L10 ;接通1#输出后转检测2#端口
- L02: JB 01H,L03 ;判断1#输出是高电平还是低电平
- CLR SC01# ;1#输出是高电平的且不为0%或100#的按参数运行
- DEC 50H ;参数减法,直到为0
- MOV A,50H
- JNZ L10 ;参数减到0,未到0的转检测2#端口
- CLR C ;参数减到0,开始转为关闭,清空C
- MOV A,#100 ;关闭的时间参数=100-原设定的参数
- SUBB A,30H ;原设定的参数放在30H
- MOV 50H,A ;关闭的时间参数放在50H
- SETB 01H ;置位,为1表示输出状态由高电平转为低电平
- L03: SETB SC01# ;按设定的时间参数高电平输出完后转为低电平输出
- DEC 50H ;参数减法,直到为0
- MOV A,50H
- JNZ L10 ;参数减到0,未到0的转检测2#端口
- MOV 50H,30H ;低电平按设定的时间参数输出完后返回转为高电平输出
- CLR 01H ;清标志位,为0表示输出状态由低电平转为高电平
- L10: MOV A,31H ;以下以此类推
- JNZ L11
- SETB SC02#
- SJMP L20
- L11: CJNE A,#100,L12
- CLR SC02#
- SJMP L20
- L12: JB 02H,L13
- CLR SC02#
- DEC 51H
- MOV A,51H
- JNZ L20
- CLR C
- MOV A,#100
- SUBB A,31H
- MOV 51H,A
- SETB 02H
- L13: SETB SC02#
- DEC 51H
- MOV A,51H
- JNZ L20
- MOV 51H,31H
- CLR 02H
- L20: MOV A,32H
- JNZ L21
- SETB SC03#
- SJMP L30
- L21: CJNE A,#100,L22
- CLR SC03#
- SJMP L30
- L22: JB 03H,L23
- CLR SC03#
- DEC 52H
- MOV A,52H
- JNZ L30
- CLR C
- MOV A,#100
- SUBB A,32H
- MOV 52H,A
- SETB 03H
- L23: SETB SC03#
- DEC 52H
- MOV A,52H
- JNZ L30
- MOV 52H,32H
- CLR 03H
- L30: MOV A,33H
- JNZ L31
- SETB SC04#
- SJMP L40
- L31: CJNE A,#100,L32
- CLR SC04#
- SJMP L40
- L32: JB 04H,L33
- CLR SC04#
- DEC 53H
- MOV A,53H
- JNZ L40
- CLR C
- MOV A,#100
- SUBB A,33H
- MOV 53H,A
- SETB 04H
- L33: SETB SC04#
- DEC 53H
- MOV A,53H
- JNZ L40
- MOV 53H,33H
- CLR 04H
- L40: MOV A,34H
- JNZ L41
- SETB SC05#
- SJMP L50
- L41: CJNE A,#100,L42
- CLR SC05#
- SJMP L50
- L42: JB 05H,L43
- CLR SC05#
- DEC 54H
- MOV A,54H
- JNZ L50
- CLR C
- MOV A,#100
- SUBB A,34H
- MOV 54H,A
- SETB 05H
- L43: SETB SC05#
- DEC 54H
- MOV A,54H
- JNZ L50
- MOV 54H,34H
- CLR 05H
- L50: MOV A,35H
- JNZ L51
- SETB SC06#
- SJMP L60
- L51: CJNE A,#100,L52
- CLR SC06#
- SJMP L60
- L52: JB 06H,L53
- CLR SC06#
- DEC 55H
- MOV A,55H
- JNZ L60
- CLR C
- MOV A,#100
- SUBB A,35H
- MOV 55H,A
- SETB 06H
- L53: SETB SC06#
- DEC 55H
- MOV A,55H
- JNZ L60
- MOV 55H,35H
- CLR 06H
- L60: MOV A,36H
- JNZ L61
- SETB SC07#
- SJMP L70
- L61: CJNE A,#100,L62
- CLR SC07#
- SJMP L70
- L62: JB 07H,L63
- CLR SC07#
- DEC 56H
- MOV A,56H
- JNZ L70
- CLR C
- MOV A,#100
- SUBB A,36H
- MOV 56H,A
- SETB 07H
- L63: SETB SC07#
- DEC 56H
- MOV A,56H
- JNZ L70
- MOV 56H,36H
- CLR 07H
- L70: MOV A,37H
- JNZ L71
- SETB SC08#
- SJMP L80
- L71: CJNE A,#100,L72
- CLR SC08#
- SJMP L80
- L72: JB 08H,L73
- CLR SC08#
- DEC 57H
- MOV A,57H
- JNZ L80
- CLR C
- MOV A,#100
- SUBB A,37H
- MOV 57H,A
- SETB 08H
- L73: SETB SC08#
- DEC 57H
- MOV A,57H
- JNZ L80
- MOV 57H,37H
- CLR 08H
- L80: MOV A,38H
- JNZ L81
- SETB SC09#
- SJMP L90
- L81: CJNE A,#100,L82
- CLR SC09#
- SJMP L90
- L82: JB 09H,L83
- CLR SC09#
- DEC 58H
- MOV A,58H
- JNZ L90
- CLR C
- MOV A,#100
- SUBB A,38H
- MOV 58H,A
- SETB 09H
- L83: SETB SC09#
- DEC 58H
- MOV A,58H
- JNZ L90
- MOV 58H,38H
- CLR 09H
- L90: MOV A,39H
- JNZ L91
- SETB SC10#
- SJMP LA0
- L91: CJNE A,#100,L92
- CLR SC10#
- SJMP LA0
- L92: JB 0AH,L93
- CLR SC10#
- DEC 59H
- MOV A,59H
- JNZ LA0
- CLR C
- MOV A,#100
- SUBB A,39H
- MOV 59H,A
- SETB 0AH
- L93: SETB SC10#
- DEC 59H
- MOV A,59H
- JNZ LA0
- MOV 59H,39H
- CLR 0AH
- LA0: MOV A,3AH
- JNZ LA1
- SETB SC11#
- SJMP LB0
- LA1: CJNE A,#100,LA2
- CLR SC11#
- SJMP LB0
- LA2: JB 0BH,LA3
- CLR SC11#
- DEC 5AH
- MOV A,5AH
- JNZ LB0
- CLR C
- MOV A,#100
- SUBB A,3AH
- MOV 5AH,A
- SETB 0BH
- LA3: SETB SC11#
- DEC 5AH
- MOV A,5AH
- JNZ LB0
- MOV 5AH,3AH
- CLR 0BH
- LB0: MOV A,3BH
- JNZ LB1
- SETB SC12#
- SJMP LC0
- LB1: CJNE A,#100,LB2
- CLR SC12#
- SJMP LC0
- LB2: JB 0CH,LB3
- CLR SC12#
- DEC 5BH
- MOV A,5BH
- JNZ LC0
- CLR C
- MOV A,#100
- SUBB A,3BH
- MOV 5BH,A
- SETB 0CH
- LB3: SETB SC12#
- DEC 5BH
- MOV A,5BH
- JNZ LC0
- MOV 5BH,3BH
- CLR 0CH
- LC0: MOV A,3CH
- JNZ LC1
- SETB SC13#
- SJMP LD0
- LC1: CJNE A,#100,LC2
- CLR SC13#
- SJMP LD0
- LC2: JB 0DH,LC3
- CLR SC13#
- DEC 5CH
- MOV A,5CH
- JNZ LD0
- CLR C
- MOV A,#100
- SUBB A,3CH
- MOV 5CH,A
- SETB 0DH
- LC3: SETB SC13#
- DEC 5CH
- MOV A,5CH
- JNZ LD0
- MOV 5CH,3CH
- CLR 0DH
- LD0: MOV A,3DH
- JNZ LD1
- SETB SC14#
- SJMP LE0
- LD1: CJNE A,#100,LD2
- CLR SC14#
- SJMP LE0
- LD2: JB 0EH,LD3
- CLR SC14#
- DEC 5DH
- MOV A,5DH
- JNZ LE0
- CLR C
- MOV A,#100
- SUBB A,3DH
- MOV 5DH,A
- SETB 0EH
- LD3: SETB SC14#
- DEC 5DH
- MOV A,5DH
- JNZ LE0
- MOV 5DH,3DH
- CLR 0EH
- LE0: MOV A,3EH
- JNZ LE1
- SETB SC15#
- SJMP LF0
- LE1: CJNE A,#100,LE2
- CLR SC15#
- SJMP LF0
- LE2: JB 0FH,LE3
- CLR SC15#
- DEC 5EH
- MOV A,5EH
- JNZ LF0
- CLR C
- MOV A,#100
- SUBB A,3EH
- MOV 5EH,A
- SETB 0FH
- LE3: SETB SC15#
- DEC 5EH
- MOV A,5EH
- JNZ LF0
- MOV 5EH,3EH
- CLR 0FH
- LF0: MOV A,3FH
- JNZ LF1
- SETB SC16#
- SJMP LFA
- LF1: CJNE A,#100,LF2
- CLR SC16#
- SJMP LFA
- LF2: JB 10H,LF3
- CLR SC16#
- DEC 5FH
- MOV A,5FH
- JNZ LFA
- CLR C
- MOV A,#100
- SUBB A,3FH
- MOV 5FH,A
- SETB 10H
- LF3: SETB SC16#
- DEC 5FH
- MOV A,5FH
- JNZ LFA
- MOV 5FH,3FH
- CLR 10H
- LFA: MOV A,40H
- JNZ LF10
- SETB SC17#
- SJMP LFB
- LF10: CJNE A,#100,LF11
- CLR SC17#
- SJMP LFB
- LF11: JB 11H,LF12
- CLR SC17#
- DEC 60H
- MOV A,60H
- JNZ LFB
- CLR C
- MOV A,#100
- SUBB A,40H
- MOV 60H,A
- SETB 11H
- LF12: SETB SC17#
- DEC 60H
- MOV A,60H
- JNZ LFB
- MOV 60H,40H
- CLR 11H
- LFB: MOV A,41H
- JNZ LF20
- SETB SC18#
- SJMP LFC
- LF20: CJNE A,#100,LF21
- CLR SC18#
- SJMP LFC
- LF21: JB 12H,LF22
- CLR SC18#
- DEC 61H
- MOV A,61H
- JNZ LFC
- CLR C
- MOV A,#100
- SUBB A,41H
- MOV 61H,A
- SETB 12H
- LF22: SETB SC18#
- DEC 61H
- MOV A,61H
- JNZ LFC
- MOV 61H,41H
- CLR 12H
- LFC: MOV A,42H
- JNZ LF30
- SETB SC19#
- SJMP LFD
- LF30: CJNE A,#100,LF31
- CLR SC19#
- SJMP LFD
- LF31: JB 13H,LF32
- CLR SC19#
- DEC 62H
- MOV A,62H
- JNZ LFD
- CLR C
- MOV A,#100
- SUBB A,42H
- MOV 62H,A
- SETB 13H
- LF32: SETB SC19#
- DEC 62H
- MOV A,62H
- JNZ LFD
- MOV 62H,42H
- CLR 13H
- LFD: MOV A,43H
- JNZ LF40
- SETB SC20#
- SJMP LFE
- LF40: CJNE A,#100,LF41
- CLR SC20#
- SJMP LFE
- LF41: JB 14H,LF42
- CLR SC20#
- DEC 63H
- MOV A,63H
- JNZ LFE
- CLR C
- MOV A,#100
- SUBB A,43H
- MOV 63H,A
- SETB 14H
- LF42: SETB SC20#
- DEC 63H
- MOV A,63H
- JNZ LFE
- MOV 63H,43H
- CLR 14H
- LFE: MOV A,44H
- JNZ LF50
- SETB SC21#
- SJMP LFF
- LF50: CJNE A,#100,LF51
- CLR SC21#
- SJMP LFF
- LF51: JB 15H,LF52
- CLR SC21#
- DEC 64H
- MOV A,64H
- JNZ LFF
- CLR C
- MOV A,#100
- SUBB A,44H
- MOV 64H,A
- SETB 15H
- LF52: SETB SC21#
- DEC 64H
- MOV A,64H
- JNZ LFF
- MOV 64H,44H
- CLR 15H
- LFF: MOV A,45H
- JNZ LF60
- SETB SC22#
- SJMP LFG
- LF60: CJNE A,#100,LF61
- CLR SC22#
- SJMP LFG
- LF61: JB 16H,LF62
- CLR SC22#
- DEC 65H
- MOV A,65H
- JNZ LFG
- CLR C
- MOV A,#100
- SUBB A,45H
- MOV 65H,A
- SETB 16H
- LF62: SETB SC22#
- DEC 65H
- MOV A,65H
- JNZ LFG
- MOV 65H,45H
- CLR 16H
- LFG: MOV A,46H
- JNZ LF70
- SETB SC23#
- SJMP LFH
- LF70: CJNE A,#100,LF71
- CLR SC23#
- SJMP LFH
- LF71: JB 17H,LF72
- CLR SC23#
- DEC 66H
- MOV A,66H
- JNZ LFH
- CLR C
- MOV A,#100
- SUBB A,46H
- MOV 66H,A
- SETB 17H
- LF72: SETB SC23#
- DEC 66H
- MOV A,66H
- JNZ LFH
- MOV 66H,46H
- CLR 17H
- LFH: MOV A,47H
- JNZ LF80
- SETB SC24#
- SJMP LFI
- LF80: CJNE A,#100,LF81
- CLR SC24#
- SJMP LFI
- LF81: JB 18H,LF82
- CLR SC24#
- DEC 67H
- MOV A,67H
- JNZ LFI
- CLR C
- MOV A,#100
- SUBB A,47H
- MOV 67H,A
- SETB 18H
- LF82: SETB SC24#
- DEC 67H
- MOV A,67H
- JNZ LFI
- MOV 67H,47H
- CLR 18H
- ;------------------------------------
- ;等待10mS到
- ;------------------------------------
- LFI: LCALL DISP ;调用显示程序
- L123: MOV A,6FH
- MOV KMWDT,#00111100B;设置看门狗
- CJNE A,#01H,L123
- MOV 6FH,#00H
- LJMP L1
- ;------------------------------------
- z;显示转化程序,48H放区域值,49H放到参数值,转换后6AH放区域值高位,
- ;6BH放区域值低位,6CH、6DH、6EH放参数值,
- ;------------------------------------
- LEDXS1:MOV B,#10 ;显示程序,为拆分计数值送显示器作准备
- MOV A,48H ;余数作个位
- DIV AB ;将计数值除以10,高位进A,余数进B
- MOV 6BH,B
- JNZ LOOP1
- MOV 6AH,#10
- SJMP LOOP2
- LOOP1:MOV 6AH,A
- LOOP2:MOV A,#2FH
- ADD A,48H
- MOV R1,0E0H
- MOV 49H,@R1
- MOV B,#10 ;显示程序,为拆分计数值送显示器作准备
- MOV A,49H ;余数作个位
- DIV AB ;将计数值除以10,高位进A,余数进B
- MOV 6EH,B
- MOV B,#10
- DIV AB
- MOV 6DH,B
- JNZ LOOP3
- MOV 6CH,#10
- SJMP LOOP4
- LOOP3:MOV 6CH,A
- LOOP4:LCALL DISP
- RET
- ;------------------------------------
- ;显示程序
- ;------------------------------------
- DISP: SETB XS1A2 ;P3.0端口置1
- SETB XSCLK ;P3.1端口置1
- MOV SCON,#00H ;初始化串行口方式0
- MOV R2,#05H ;显示5位数
- MOV R1,#6EH ;60H-65H为显示缓冲区
- MOV DPTR,#SETTAB ;字形表的入口地址
- L00P: MOV A,@R1 ;取最高位的待显示数据
- MOVC A,@A+DPTR ;查表获取字形码
- MOV SBUF,A ;送串口显示
- DELAY:JNB TI,DELAY ;等待发送完毕
- CLR TI ;清发送标志
- DEC R1 ;指针下移一位,准备取下一个待显示数
- DJNZ R2,L00P ;直到6个数据全显示完。
- CLR XS1A2 ;P3.0端口置0
- CLR XSCLK ;P3.1端口置0
- RET
- SETTAB:DB 03H 9FH 25H 0DH 99H 49H 41H 1FH 01H 09H 0FFH
- ; 0 1 2 3 4 5 6 7 8 9 消隐码
- ;------------------------------------
- ;10mS时间中断
- ;------------------------------------
- INTT0:PUSH ACC ;10mS时间中断
- PUSH PSW
- MOV TH0,#0D8H ;重置时间参数为10mS(晶振为12M)
- MOV TL0,#0F0H
- MOV KMWDT,#00111100B;设置看门狗
- MOV 6FH,#01H ;6FH为10mS时间到标志
- POP PSW
- POP ACC
- RETI
- YS1: MOV R6,#70H ;延时子程序
- Y10: MOV R7,#0FFH
- Y11: NOP
- NOP
- NOP
- DJNZ R7,Y11
- MOV KMWDT,#00111100B;设置看门狗
- DJNZ R6,Y10
- RET
- ;------------------------------------
- ;EEPROM操作程序
- ;------------------------------------
- ;-----------------------------------------------------
- ;写N字节数据子程序
- ;-----------------------------------------------------
- WRITE_DATA:
- MOV R0,#00H ;数据写入首地址
- MOV R1,#30H ;
- WR_LOOP: MOV B,@R1
- LCALL WRITE_BYTE ;将查表结果写入24C02
- INC R0 ;地址+1
- INC R1
- MOV KMWDT,#00111100B;设置看门狗
- CJNE R1,#48H,WR_LOOP;24个数写入完毕?
- RET
- ;-----------------------------------------------------
- ;读N字节数据子程序
- ;从24C02读出数据
- ;-----------------------------------------------------
- READ_DATA:
- MOV R0,#00H ;设定读取的初始地址
- MOV R1,#30H ;
- RE_LOOP: LCALL READ_BYTE ;读EEPROM
- MOV KMWDT,#00111100B;设置看门狗
- LCALL STOP
- MOV @R1,A
- INC R0 ;地址+1
- INC R1
- CJNE R1,#48H,RE_LOOP;24个数写入完毕?
- RET
- ;----------------------------------------------------
- ;写操作子程序
- ;输入参数: R0---要写入的地址,B---要写入的数据
- ;----------------------------------------------------
- WRITE_BYTE:
- LCALL START
- MOV A,#0A0H
- LCALL SENDBYTE
- LCALL WAITACK
- MOV KMWDT,#00111100B ;设置看门狗
- MOV A,R0
- LCALL SENDBYTE
- LCALL WAITACK
- MOV A,B
- LCALL SENDBYTE
- LCALL WAITACK
- LCALL STOP
- LCALL DELAY_5MS ;每写入1个字节,延时若干MS
- RET
- ;----------------------------------------------------
- ;读操作子程序
- ;输入参数:R0---要读的字节地址,
- ;输出参数: A---结果
- ;----------------------------------------------------
- READ_BYTE:
- LCALL START
- MOV A,#0A0H
- LCALL SENDBYTE
- LCALL WAITACK
- MOV A,R0
- LCALL SENDBYTE
- LCALL WAITACK
- LCALL START
- MOV A,#0A1H
- LCALL SENDBYTE
- LCALL WAITACK
- LCALL RCVBYTE
- RET
- ;-----------------------------------------------------
- ;从IIC总线上接收一个字节数据
- ;出口参数:A---接收数据存放在A中
- ;-----------------------------------------------------
- RCVBYTE:
- MOV R7,#08 ;一个字节共接收8位数据
- CLR A
- SETB SDA ;释放SDA数据线
- R_BYTE:
- CLR SCL
- NOP
- NOP
- NOP
- NOP
- SETB SCL ;启动一个时钟周期,读总线
- NOP
- NOP
- NOP
- NOP
- MOV C,SDA ;将SDA状态读入C
- RLC A ;结果移入A
- SETB SDA ;释放SDA数据线
- DJNZ R7,R_BYTE ;判断8位数据是否接收完全?
- RET
- ;----------------------------------------------------
- ;向IIC总线发送一个字节数据
- ;入口参数:A---待发送数据存放在A中
- ;----------------------------------------------------
- SENDBYTE:
- MOV R7,#08
- S_BYTE:
- RLC A
- MOV SDA,C
- SETB SCL
- NOP
- NOP
- NOP
- NOP
- CLR SCL
- DJNZ R7,S_BYTE ;8位发送完毕?
- RET
- ;-----------------------------------------------------
- ;等待应答信号
- ;等待从机返回一个响应信号
- ;-----------------------------------------------------
- WAITACK:
- CLR SCL
- SETB SDA ;释放SDA信号线
- NOP
- NOP
- SETB SCL
- NOP
- NOP
- NOP
- MOV C,SDA
- JC WAITACK ;SDA为低电平,返回了响应信号
- CLR SDA
- CLR SCL
- RET
- ;----------------------------------------------------
- ;启动信号子程序
- ;----------------------------------------------------
- START:
- SETB SDA
- SETB SCL
- NOP
- CLR SDA
- NOP
- NOP
- NOP
- NOP
- CLR SCL
- RET
- ;----------------------------------------------------
- ;停止信号子程序
- ;----------------------------------------------------
- STOP: MOV KMWDT,#00111100B;设置看门狗
- CLR SDA
- NOP
- SETB SCL
- NOP
- NOP
- NOP
- NOP
- SETB SDA
- NOP
- NOP
- CLR SCL
- CLR SDA
- RET
- ;----------------------------------------------------
- ;延时5MS子程序
- ;输入参数:5MS
- ;输出参数: 无
- ;影响资源: R5,R6等
- ;----------------------------------------------------
- DELAY_5MS:
- MOV R6,#10
- DE_LP:
- MOV R5,#250
- DJNZ R5,$
- MOV KMWDT,#00111100B;设置看门狗
- DJNZ R6,DE_LP
- RET
- ;------------------------------------
- ;软件陷阱
- ;------------------------------------
- ORG 0B00H ;软件陷阱
- NOP
- NOP
- NOP
- LJMP KS
- END
复制代码
|
|