📄 pc16bios.a51
字号:
;
; Copyright (c) Johnson Electric Industry Mfty. Ltd.
; Filename : PC16Bios.a51
; CPU Type : AT89S8252
; Revision : 1.0
; Date :
; Description : AT89S8252 for 16 input 8 output
; C call assemble subroutine
;----------------------------------------------------------------------------
$list
;; $nolist
; $nomod51
name clock
;----------------------------------------------------------------------------
; $include (\franklin\include\define.inc)
$include (define.inc)
;----------------------------------------------------------------------------
public init_system,_output_port,_scan_manual
public _current_time,_delay,_input_port
public _get_outstus,_get_key,_disp_pilot
;----------------------------------------------------------------------------
; Declaration any constant (typeless) numbers here.
MSB_PERIOD set 0b2h ; b1e0h=delay10ms
LSB_PERIOD set 0e0h ; 63c0h=delay20ms
;----------------------------------------------------------------------------
; define data segment for varible
data_segment segment data
rseg data_segment
output_buf: ds 1
input_stus: ds 1
port0_stus: ds 1
port2_stus: ds 1
port3_stus: ds 1
input_buf1: ds 3
input_buf2: ds 3 ; software filte for input signal
tick_clock: ds 2
;----------------------------------------------------------------------------
; BIT SEGMENT: reserves space in BIT RAM (delete segment if not used!)
bit_seg_name segment bit ; segment for BIT RAM.
rseg bit_seg_name ; switch to this bit segment
scan_flag: dbit 1
;----------------------------------------------------------------------------
; cseg at 0 ; absolute Code SEGment AT address 0
; ljmp INIT_SYSTEM ; install RESET location (jump to start)
; code segment start address
system_start segment code ; switch to this code segment
rseg system_start
using 0 ; state register_bank used
init_system: mov tl0,#LSB_PERIOD ;LSB_PERIOD=0E0H MSB_PERIOD=0B2H
mov th0,#MSB_PERIOD ; set timer0 interrupt period 10ms for @24MHZ
mov tl1,#0ech
mov th1,#0cbh ; set timer1 interrupt period 6.67ms for @24MHZ
mov tmod,#00010001b ; select mode 1 16 counter
mov ie,#10101010b ; enable globe and timer0&timer1&timer2 interrupt
setb tr0 ; start timer0
setb tr1 ; start timer1
mov r5,#10
powerondelay: call delay5ms ; software delay 1 second
djnz r5,powerondelay ; for SPI serial programming port
ret
;----------------------------------------------------------------------------
; PC16I8O input port c call function prototype char _input_port(char c)
;
_input_port: clr c ;if r7=#0fh
mov a,r7 ;r7=#0fh (00001111b)
xrl a,#080h ;(00001111@1000000)=10001111b
subb a,#089h ;10001111b-10001001b=00000110b
jnc in_port1 ;Cy=0 jump in_port1
mov r6,port0_stus
mov input_stus,r6
sjmp in_port2
in_port1: mov r6,port2_stus ;
mov input_stus,r6 ;
in_port2: mov a,r7 ;a=00001111b
dec a ;a=00001110b
cjne a,#010h,in_port3 ;00001110<>00010000 Cy=1 (a<#010h)
in_port3: jc $ + 5h
ljmp in_exit
mov dptr,#stus_vector
mov r0,a
add a,r0 ;a=00011100
add a,r0 ;a=00111000
jmp @a+dptr
;
stus_vector: ljmp stus_port1
ljmp stus_port2
ljmp stus_port3
ljmp stus_port4
ljmp stus_port5
ljmp stus_port6
ljmp stus_port7
ljmp stus_port8
ljmp stus_port9
ljmp stus_port10
ljmp stus_port11
ljmp stus_port12
ljmp stus_port13
ljmp stus_port14
ljmp stus_port15
ljmp stus_port16
;
stus_port1: anl input_stus,#01H
sjmp in_exit
;
stus_port2: anl input_stus,#02H
sjmp in_exit
;
stus_port3: anl input_stus,#04H
sjmp in_exit
;
stus_port4: anl input_stus,#08H
sjmp in_exit
;
stus_port5: anl input_stus,#010H
sjmp in_exit
;
stus_port6: anl input_stus,#020H
sjmp in_exit
;
stus_port7: anl input_stus,#040H
sjmp in_exit
;
stus_port8: anl input_stus,#080H
sjmp in_exit
;
stus_port9: anl input_stus,#01H
sjmp in_exit
;
stus_port10: anl input_stus,#02H
sjmp in_exit
;
stus_port11: anl input_stus,#04H
sjmp in_exit
;
stus_port12: anl input_stus,#08H
sjmp in_exit
;
stus_port13: anl input_stus,#010H
sjmp in_exit
;
stus_port14: anl input_stus,#020H
sjmp in_exit
;
stus_port15: anl input_stus,#040H
sjmp in_exit
;
stus_port16: anl input_stus,#080H
in_exit: mov a,input_stus
cjne a,#00,in_exit1
mov r7,#ON
jmp in_exit2
in_exit1: mov r7,#OFF
in_exit2: ret
;----------------------------------------------------------------------------
; PC16I8O output port C call function prototype
; void _output_port(char c,char s) r7=c(address), r5=s(command: on or off)
;
_output_port: mov a,r5 ;
cjne a,#01,out_port1 ;
mov r5,#OFF ;
jmp out_port2 ;
out_port1: mov r5,#ON ;begain give command (1 or 0 ) for r5
out_port2: mov r6,p1 ;
mov output_buf,r6 ;restore p1 port signal to output_buf
mov a,r7 ;
dec a ;
cjne a,#08h,out_port3 ;
out_port3: jc $ + 5h ;
ljmp out_exit ;
mov dptr,#out_vector ;
mov r0,a ;
add a,r0 ;
add a,r0 ;
jmp @a+dptr ;
;
out_vector: ljmp port1_out
ljmp port2_out
ljmp port3_out
ljmp port4_out
ljmp port5_out
ljmp port6_out
ljmp port7_out
ljmp port8_out
;
port1_out: mov a,r5
cjne a,#01h,port1_out1
orl output_buf,#01H
ljmp out_exit
port1_out1: anl output_buf,#0FEH
ljmp out_exit
port2_out: mov a,r5
cjne a,#01h,port2_out1
orl output_buf,#02h
ljmp out_exit
port2_out1: anl output_buf,#0fdh
sjmp out_exit
port3_out: mov a,r5
cjne a,#01h,port3_out1
orl output_buf,#04h
sjmp out_exit
port3_out1: anl output_buf,#0fbh
sjmp out_exit
port4_out: mov a,r5
cjne a,#01h,port4_out1
orl output_buf,#08h
sjmp out_exit
port4_out1: anl output_buf,#0f7h
sjmp out_exit
port5_out: mov a,r5
cjne a,#01h,port5_out1
orl output_buf,#010h
sjmp out_exit
port5_out1: anl output_buf,#0efh
sjmp out_exit
port6_out: mov a,r5
cjne a,#01h,port6_out1
orl output_buf,#020h
sjmp out_exit
port6_out1: anl output_buf,#0dfh
sjmp out_exit
port7_out: mov a,r5
cjne a,#01h,port7_out1
orl output_buf,#040h
sjmp out_exit
port7_out1: anl output_buf,#0bfh
sjmp out_exit
port8_out: mov a,r5
cjne a,#01h,port8_out1
orl output_buf,#080h
sjmp out_exit
port8_out1: anl output_buf,#07fh
out_exit: mov p1,output_buf
ret
;----------------------------------------------------------------------------
_get_outstus: mov r6,p1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -