[an error occurred while processing this directive]
Вот пример, содержащий в
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)

миниатюрный аудио-видеорекордер mAVR

Отправлено scorpion 15 ноября 2006 г. 23:43
В ответ на: Под отправлено scorpion 15 ноября 2006 г. 23:16

себе и опрос клавиатуры по таймеру. Покопайся, может поможет (ASM-51):

;************************
;* F osc = 22.118 mgc *
;************************


; MEMORY DEFINITION
;--------------------
memtop_0 equ 256 ;top of internal ram (indirect addr.)
temp_disp_1 equ memtop_0-32 ;temp. display data buffer
temp_disp_2 equ temp_disp_1-32 ;temp. display data buffer
temp_buf equ temp_disp_2-64 ;work buffer

memtop_1 equ 128 ;top of internal ram
key_code_buf equ memtop_1-6 ;keyboard buffer
data_buf equ key_code_buf-32 ;work buffer(search,transfer...)
disp_buf equ data_buf ;display buffer
loop_cnt equ data_buf-1 ;index counter
inc_rec_pnt equ loop_cnt-1 ;incoming sms rec_pointer
push_tr_pnt equ inc_rec_pnt-1 ;pointer for next push transfer
pop_tr_pnt equ push_tr_pnt-1 ;pointer for next pop transfer

stack_pointer equ 26h ;stack pointer

sys_reg_byte equ 20h ;register with system bits
key_flags equ 21h ;register with key flags
sys_pointer equ 22h ;register with menager bits
mast_status equ 25h ;master status

; BIT RAM MEMORY DEFINITION
;--------------------------
;----address 20h
led_bit equ 0 ;led bit
rs_dir_bit equ 1 ;rs-485 direction
rd_wr_bit equ 2 ;rd/wr of lcd display
kby_0 equ 3 ;scan 0 output
kby_1 equ 4 ;scan 1 output
kby_2 equ 5 ;scan 2 output
kby_3 equ 6 ;scan 3 output
kby_4 equ 7 ;scan 4 output
;----address 21h
key_code_rdy equ 8 ;key ready flag
up_rdy equ 9 ;'up' key flag
down_rdy equ 10 ;'down' key flag
star_rdy equ 11 ;'star' key flag
dies_rdy equ 12 ;'dies' key flag

;----address 22h
tr_sync_flag equ 16 ;work rs_tr_int flag
sound_long equ 17 ;long sound flag
lcd_line_bit equ 18 ;lcd line number
msec_bit equ 19 ;work trigger
sel_1 equ 20 ;select proc_1 enable
sel_2 equ 21 ;select proc_2 enable
sel_3 equ 22 ;select proc_3 enable
sel_4 equ 23 ;select proc_4 enable
;----address 23h
secund_bit equ 24 ;secund trigger
secondary_disp equ 25 ;flag settings after store display
di_kb_bit equ 26 ;disable keyboard flag
tim_exit_en equ 27 ;timout exit enable flag
main_mode_flag equ 28 ;main mode indicator
unvis_flag equ 29 ;unvisible message flag
empty_flag equ 30 ;empty flag
init_sem_bit equ 31 ;work flag
;----address 24h
time_corr_bit equ 32 ;time correct flag (+3/+4 hour)
unvis_sound equ 33 ;unvisible sound indicator
end_trans_bit equ 34 ;user flag
low_nib_flag equ 35 ;convert proc. flag
rs_rec_rdy equ 36 ;rs_485 string ready to read
rs_tr_rdy equ 37 ;rs_485 string transmit end
reset_flag equ 38 ;system reset command indicator
time_upd_bit equ 39 ;update real time trigger
;----address 25h
sms_tr_busy equ 40 ;gsm module not ready to transmit
sms_rec_rdy equ 41 ;new sms ready in gsm module
gsm_fault equ 42 ;gsm module fault
crc_error equ 43 ;error crc in gsm module
ring_bit equ 44 ;gsm ring indicator
talk_bit equ 45 ;gsm talk mode indicator
gps_bit equ 46 ;gps valid indicator
mast_stat_7 equ 47 ;don't care

; CONSTANTS DEFINITION
;---------------------
tmodi equ 00100001B ;timer mode,t1-auto,t0-16bit
rs_speed equ 256-3*2 ;speed of rs-232 t1-9600
t_start equ 01010001b ;const for t0,t1 start,int0-dawn edge
rs_modi equ 01010000b ;receiver-open,8-bit
int_modi equ 00000010b ;tim0 enable,global bit-disable
t0_h_const equ high(65535-3682) ;2 ms with sys_clock 22.118 mgc
t0_l_const equ low(65535-3682) ;2 ms with sys_clock 22.118 mgc
spi_const equ 01011101b ;speed version
tone equ 64000 ;tone const
dd_ram_add1 equ 10000000b ;DDram address of LCD 1-line
dd_ram_add2 equ 11000000b ;DDram address of LCD 2-line
user_work_page equ 0 ;first page of external ram
rs_rec_page equ 0100h ;page to reception data
rs_tr_page equ 0200h ;page with sours data to transmit
register_page equ 0300h ;register data
push_rs_page equ 0400h ;outgoing rs data page
sem_sms_page equ 1000h ;incoming semantic sms page
semantic_area equ 7000h ;from this point semantic sms,phone...
var_area equ 7000h+256*9 ;system variables
disp_addr equ 0c000h ;address of LCD display
sys_addr equ 08000h ;address of system register

cod_star equ 0ah ;cod '*'
cod_dies equ 0bh ;cod '#'
cod_f1 equ 0ch ;register mode button
cod_f2 equ 0dh ;outgoing sms mode button
cod_f3 equ 0eh ;direct call mode button
cod_up equ 0fh ;'+' button
cod_down equ 10h ;'-' button


; SFR AT89s8252 DEFINITION
;-----------------------------
spi_control equ 0d5h ;SPI control register
spi_stat equ 0aah ;SPI status register
spi_data equ 086h ;SPI data register
th2 equ 0cdh ;high byte of timer2
tl2 equ 0cch ;low byte of timer2
dpl_2 equ 084h ;low byte of dptr_2
dph_2 equ 085h ;high byte of dptr_2
cap_h equ 0cbh ;high capture of timer2
cap_l equ 0cah ;low capture of timer2
t2con equ 0c8h ;timer 2 mode
t2mod equ 0c9h ;timer 2 mode
wmcon equ 96h ;direct address of w_dog,mem_control
pcon equ 87h ;power control register

;---- bank_0
r0b0 equ 0 ;direct address of register
r1b0 equ 1 ;direct address of register
r2b0 equ 2 ;direct address of register
r3b0 equ 3 ;direct address of register
r4b0 equ 4 ;direct address of register
r5b0 equ 5 ;direct address of register
r6b0 equ 6 ;direct address of register
r7b0 equ 7 ;direct address of register
;---- bank_1 (timer interrupt)
key_buf_pnt equ 8 ;keyboard work register(r0b1)
m_tim0 equ 9 ;work delay counter
scan_cnt equ 0ah ;keyboard scan counter (r2b1)
push_cnt equ 0bh ;keyboard push counter (r3b1)
temp_key equ 0ch ;keyboard work register(r4b1)
beep_cnt equ 0dh ;beep length counter (r5b1)
int_cnt equ 0eh ;1/50 interrupt devider(100 ms)
secund_cnt equ 0fh ;1/10 interrupt devider(1 sec)
;---- bank_2
rs_rec_pnt equ 10h ;rec_data_pointer
rs_tr_pnt equ 11h ;tr_data_pointer
rs_tr_cnt equ 12h ;tr_data_counter
temp_nib equ 13h ;rs_int work register
push_disp_pnt equ 14h ;push register pointer
pop_disp_pnt equ 15h ;pop register pointer
disp_timout equ 16h ;display event timout
sound_delay equ 17h ;sound delay
;---- bank_3
sms_snd_cnt equ 18h ;unvisible sms sound counter
sound_pause equ 19h ;sound pause
consol_cmd equ 1ah ;console status byte
con_data_1 equ 1bh ;console data (first byte)
con_data_2 equ 1ch ;console data (second byte)
m_tim_long equ 1dh ;long user delay
tim_exit_cnt equ 1eh ;timout exit from push_button proc.
light_cnt equ 1fh ;lcd light delay

; PORT DEFINITION
;----------------
;--- port 0 - data port
;--- port 2 -address port

;--- port 1
beep_port bit p1.0 ;sound output
kbx_0 bit p1.1 ;keyboard line input
kbx_1 bit p1.2 ;keyboard line input
kbx_2 bit p1.3 ;keyboard line input
kbx_3 bit p1.4 ;keyboard line input
sdo_port bit p1.5 ;spi data output
sdi_port bit p1.6 ;spi data input
scl_port bit p1.7 ;spi clock

;--- port 3
rx_d bit p3.0 ;rs-485 receiver
tx_d bit p3.1 ;rs-485 transmetter
reg_clock bit p3.2 ;74hc374 register clock
user_out bit p3.3 ;reserved port
ext_clock_in bit p3.4 ;32768 ext. clock
lcd_light bit p3.5 ;lcd light output
wr_port bit p3.6 ;system write signal
rd_port bit p3.7 ;system read signal

%define(wait)(
mov a,#0
cjne a,m_tim0,$
)
%define(beep_stop)(
anl t2mod,#11111101b
setb beep_port
)
%define(beep_start)(
mov th2,cap_h
mov tl2,cap_l
orl t2mod,#00000010b
)
%define(int_fl_wr)(
orl wmcon,#00010000b ;set write mode
movx @dptr,a
mov a,wmcon ;wait for write completed
jnb acc.1,$-2
anl wmcon,#11101111b
)
%define(dptr_1)(
anl wmcon,#11111011b
)
%define(dptr_2)(
orl wmcon,#00000100b
)

org 0
ljmp start

org 0bh
ljmp tim0_int ;system timer and keyboard interrupt

org 23h
ljmp rs_int ;master_pc exchange interrupt

tim0_int: ;timer_0 interrupt (bank_1 reserved)
mov th0,#t0_h_const ;2 ms with sys_clock 22.118 mgc
mov tl0,#t0_l_const ;2 ms with sys_clock 22.118 mgc
push acc
push psw
push wmcon
%dptr_1
push dph
push dpl
setb psw.3 ;make bank1
clr psw.4
dec m_tim0
djnz int_cnt,keyboard_work
mov int_cnt,#50 ;100 ms update period
setb time_upd_bit
dec m_tim_long
setb msec_bit
djnz tim_exit_cnt,$+6
mov tim_exit_cnt,#1
djnz secund_cnt,skip_work_cnt
mov secund_cnt,#10 ;1 sec update period
cpl secund_bit
djnz disp_timout,$+6
mov disp_timout,#1
djnz light_cnt,skip_sms_snd
mov light_cnt,#1
setb lcd_light ;light off
skip_sms_snd:
djnz sms_snd_cnt,skip_work_cnt
mov sms_snd_cnt,#20 ;20 sec update period
setb unvis_sound
skip_work_cnt:
cpl led_bit

mov a,sys_reg_byte
mov dptr,#sys_addr
movx @dptr,a

; mov p2,sys_reg_byte
; ---
; clr reg_clock
; setb reg_clock
keyboard_work:
djnz r5,test_kb_enable
mov r5,#1
%beep_stop
test_kb_enable:
jnb di_kb_bit,$+6 ;skip keyboard proc if it is disable
ljmp kb_exit
mov c,kbx_3
rlc a
mov c,kbx_2
rlc a
mov c,kbx_1
rlc a
mov c,kbx_0
rlc a
cpl a
anl a,#00001111b
jz next_scan ;exit if not any key push
cjne r3,#1,push_restore
mov dptr,#kbx_tab
movc a,@a+dptr
mov temp_key,a
create_key_code:
mov r5,#33
%beep_start
mov light_cnt,#30
clr lcd_light ;light on
mov a,r2
rl a
rl a
orl a,temp_key
mov dptr,#key_code_tab
movc a,@a+dptr
mov key_code_buf+5,key_code_buf+4
mov key_code_buf+4,key_code_buf+3
mov key_code_buf+3,key_code_buf+2
mov key_code_buf+2,key_code_buf+1
mov key_code_buf+1,key_code_buf
mov key_code_buf,a
mov sbuf,a
setb key_code_rdy
push_restore:
mov r3,#50 ;restore push counter
next_scan:
inc r2 ;r2b1-scan cnt
cjne r2,#5,$+5
mov r2,#0
mov a,r2
mov dptr,#scan_tab
movc a,@a+dptr
orl sys_reg_byte,#11111000b
anl sys_reg_byte,a

mov a,sys_reg_byte
mov dptr,#sys_addr
movx @dptr,a

decr_push:
djnz r3,$+4 ;r3b1-decr push cnt
mov r3,#1
kb_exit:
pop dpl
pop dph
pop wmcon
pop psw
pop acc
reti

;key_code_tab:
; db 05h ;return cod '5'
; db 00h ;return cod '0'
; db 0eh ;return cod 'F3'
; db 7fh ;dont care
; db 03h ;return cod '3'
; db 07h ;return cod '7'
; db 0fh ;return cod 'F4'
; db 7fh ;dont care
; db 06h ;return cod '6'
; db 09h ;return cod '9'
; db 10h ;return cod 'F5'
; db 7fh ;dont care
; db 02h ;return cod '2'
; db 08h ;return cod '8'
; db 0bh ;return cod '#'
; db 0ch ;return cod 'F1'
; db 01h ;return cod '1'
; db 04h ;return cod '4'
; db 0ah ;return cod '*'
; db 0dh ;return cod 'F2'

key_code_tab:
db 04h ;4
db 01h ;1
db 07h ;7
db 0ah ;*
db 05h ;5
db 02h ;2
db 08h ;8
db 00h ;0
db 06h ;6
db 03h ;3
db 09h ;9
db 0bh ;#

db 0dh ;F2
db 7fh ;---
db 0eh ;F3
db 0fh ;F4
db 7fh ;---
db 7fh ;---
db 0ch ;F1
db 10h ;F5

scan_tab:
db 11110111b
db 11101111b
db 11011111b
db 10111111b
db 01111111b

kbx_tab:
db 0,0,1,0,2,0,0,0,3


rs_int: ;rs-232 interrupt vector
push acc
push psw
push wmcon
%dptr_1
push dph
push dpl
clr psw.3 ;make bank2
setb psw.4
jbc ri,verify_header ;r0 - rec_data_pointer
clr ti ;r1 - tr_data_pointer
rs_tr_part: ;r2 - tr_data_counter
jnb end_trans_bit,rs_tr_main
clr end_trans_bit
setb rs_tr_rdy
sjmp exit_rs_int

rs_tr_main:
djnz r2,transf_high_nib
setb end_trans_bit
mov sbuf,#'#'
sjmp exit_rs_int

transf_high_nib:
jb tr_sync_flag,trasf_low_nib
setb tr_sync_flag
mov dptr,#rs_tr_page ;page with data to transfer
mov dpl,r1 ;pointer in page
movx a,@dptr
swap a
anl a,#00001111b
mov dptr,#asc_tab
movc a,@a+dptr ;get asc byte
mov sbuf,a ;next byte transfer
sjmp exit_rs_int

trasf_low_nib:
clr tr_sync_flag
mov dptr,#rs_tr_page ;page with data to transfer
mov dpl,r1 ;pointer in page
movx a,@dptr
anl a,#00001111b
mov dptr,#asc_tab
movc a,@a+dptr ;get asc byte
mov sbuf,a ;next byte transfer
inc r1
sjmp exit_rs_int

verify_header:
mov a,sbuf ;read data
cjne a,#'$',verify_rec_end
mov r0,#0 ;reset reception pointer
clr low_nib_flag
sjmp exit_rs_int
verify_rec_end:
cjne a,#'#',test_high_conv
lcall pack_rs_data
setb rs_rec_rdy
sjmp exit_rs_int
test_high_conv:
jb low_nib_flag,low_nib_conv
mov dptr,#conv_tab
clr c
subb a,#30h
movc a,@a+dptr
swap a
mov temp_nib,a
cpl low_nib_flag
sjmp exit_rs_int
low_nib_conv:
mov dptr,#conv_tab
clr c
subb a,#30h
movc a,@a+dptr
orl a,temp_nib
cpl low_nib_flag
mov dptr,#rs_rec_page ;page for reception data
mov dpl,r0 ;pointer in page
movx @dptr,a ;store next byte
inc r0 ;next receive pointer
exit_rs_int:
pop dpl
pop dph
pop wmcon
pop psw
pop acc
reti

$include(lcd_part.inc)

;********************* Main programm ********************
start:
mov sp,#stack_pointer
mov tmod,#tmodi ;set timer 0,1 mode
mov th1,#rs_speed ;set speed of rs-232
mov tl1,#rs_speed
mov th0,#t0_h_const ;2 ms with sys_clock 11.059 mgc
mov tl0,#t0_l_const ;2 ms with sys_clock 11.059 mgc
mov tcon,#t_start ;start t1
mov scon,#rs_modi ;receiver-open
mov ie,#int_modi ;tim0 int-enable,global int-disable
mov ip,#00010000b
mov cap_h,#high(tone) ;high capture of timer2
mov cap_l,#low(tone) ;low capture of timer2
mov t2con,#00000100b ;timer 2 mode
mov t2mod,#00000000b ;timer 2 mode
mov wmcon,#11100010b ;wdt-close,external ram access
clear_memory:
mov r0,#255
clear_mem_loop:
mov @r0,#0ffh
djnz r0,clear_mem_loop

clr ring_bit
clr sound_long
clr key_code_rdy
clr rs_rec_rdy
clr end_trans_bit
clr secondary_disp
setb di_kb_bit ;keyboard disable
clr tim_exit_en ;close timout exit from push_button proc.
clr p3.3
setb time_corr_bit
mov secund_cnt,#10 ;1 sec update period in interrupt
mov sms_snd_cnt,#20
mov sys_reg_byte,#11111111b
lcall set_sys_reg
mov push_disp_pnt,#0 ;push register pointer
mov pop_disp_pnt,#0 ;pop register pointer
mov disp_timout,#1 ;display event timout
mov sound_pause,#10
mov sound_delay,#20
mov consol_cmd,#0
mov inc_rec_pnt,#0
mov push_tr_pnt,#0
mov pop_tr_pnt,#0
setb ie.7
mov m_tim0,#100
%wait ;slave reset wait
lcall display_init ;init lcd display
mov beep_cnt,#100 ;beep length
%beep_start
mov m_tim0,#100
%wait ;slave reset wait
clr di_kb_bit
lcall clear_incom_sms_page
lcall clear_register_page
lcall clear_rec_page
lcall clear_tr_page
lcall clear_push_rs_page
mov light_cnt,#50 ;50 sec. light 'on'
clr lcd_light
mov rs_rec_pnt,#0 ;rec_data_pointer
mov rs_tr_pnt,#0 ;tr_data_pointer
mov rs_tr_cnt,#8 ;tr_data_counter
clr ti
clr ri
;;; setb ie.4 ;rs interrupt open
; jnb rs_rec_rdy,$ ;wait for master start_up
;--- init semantic area

setb rs_dir_bit
lcall set_sys_reg
clr p3.3

xxx:
mov dptr,#init_lable
lcall update_display
yyy:
jnb key_code_rdy,$
clr key_code_rdy
mov a,key_code_buf
add a,#30h
mov disp_buf,a
clr lcd_line_bit
lcall send_str
cpl p3.3
cpl p3.4

; lcall out_rs_byte
sjmp yyy

; mov dptr,#2000h
;www:
; mov a,#0
; movx @dptr,a
; inc dptr
; mov a,dph
; cjne a,#30h,www
; mov a,#0b2h
; movx @dptr,a
; inc dptr
; mov a,#0b4h
; movx @dptr,a
; inc dptr
; mov a,#02
; movx @dptr,a
; inc dptr
; mov a,#20h
; movx @dptr,a
; inc dptr
; mov a,#0
; movx @dptr,a
; inc dptr
; ljmp 2000h
mov m_tim0,#20
%wait ;slave reset wait
mov a,#55h
lcall out_rs_byte
mov a,#55h
lcall out_rs_byte
mov a,#55h
lcall out_rs_byte

sjmp xxx

mov consol_cmd,#5 ;read semantic stringes status at first
lcall push_to_rs
clr init_sem_bit
jnb init_sem_bit,$
lcall init_semantic
mov dptr,#init_ok_lable
lcall update_display
mov m_tim_long,#20 ;2 sec. wait for display ok_result
mov a,#0
cjne a,m_tim_long,$
;--- display system variables
lcall disp_sys_var
mov m_tim_long,#40 ;4 sec. wait for display variables
mov a,#0
cjne a,m_tim_long,$
lcall disp_phone_var
mov m_tim_long,#40 ;4 sec. wait for display variables
mov a,#0
cjne a,m_tim_long,$
clr reset_flag
main_loop:
setb main_mode_flag
lcall wait_push_button
cjne a,#cod_f1,$+6
ljmp user_view_mode ;view incoming sms,register history
cjne a,#cod_f2,$+6
ljmp transfer_sms_mode ;transfer formal sms from 'sms book'
cjne a,#cod_f3,$+6
ljmp direct_call_mode ;direct call from 'phone book'
cjne a,#cod_dies,$+6
ljmp var_view_mode ;read variables and view
sjmp main_loop
exit_to_main:
mov sp,#stack_pointer ;restore stack
mov sms_snd_cnt,#20 ;20 sec update period
clr tim_exit_en ;timout exit from push_button proc. disable
jb main_mode_flag,main_loop
mov r0,#key_code_buf
mov r2,#6
mov a,#0ffh
lcall fill_acc ;fill @r0 with acc
mov dptr,#user_work_page
lcall restore_display
sjmp main_loop

var_view_mode:
mov a,key_code_buf+2
cjne a,#cod_star,verify_secur_code

mov a,key_code_buf+1
mov dptr,#conv_num_tab
movc a,@a+dptr
mov loop_cnt,a

setb tim_exit_en
clr main_mode_flag
mov dptr,#user_work_page
lcall read_all_disp
mov dptr,#inp_help_lab
setb lcd_line_bit ;second string
lcall send_lable ;display 'HELP' in second string
ljmp transf_sms_direct

conv_num_tab:
db 9
db 0
db 1
db 2
db 3
db 4
db 5
db 6
db 7
db 8

verify_secur_code:
mov a,key_code_buf+5
cjne a,#3,main_loop
mov a,key_code_buf+4
cjne a,#2,main_loop
mov a,key_code_buf+3
cjne a,#7,main_loop
mov a,key_code_buf+2
cjne a,#6,main_loop
mov a,key_code_buf+1
cjne a,#8,main_loop
clr main_mode_flag
mov dptr,#user_work_page
lcall read_all_disp
mov dptr,#test_mode_lab
lcall update_display
wait_user_command:
jnb key_code_rdy,$
clr key_code_rdy
mov a,key_code_buf
cjne a,#cod_star,$+6
ljmp exit_to_main
cjne a,#1,$+6
ljmp main_cpu_version
cjne a,#2,$+6
ljmp consol_version
cjne a,#3,$+6
ljmp restart_system
sjmp wait_user_command

main_cpu_version:
lcall clr_display
clr lcd_line_bit ;first string
mov dptr,#main_ver_lab
lcall send_lable ;display 'MAIN' in second string
mov dptr,#var_area+224
cpu_version_more:
mov r0,#disp_buf
mov r2,#10 ;10 bytes in 'date' string
lcall rewr_from_ram
mov r2,#10 ;4 bytes in object number
mov r4,#6 ;offset in string
lcall send_part ;real time display
jb lcd_line_bit,delay_disp_version
setb lcd_line_bit
mov dptr,#var_area+234
sjmp cpu_version_more
delay_disp_version:
jnb key_code_rdy,$
clr key_code_rdy
ljmp exit_to_main

consol_version:
lcall clr_display
clr lcd_line_bit ;first string
mov dptr,#cons_ver_lab
lcall send_lable ;display 'MAIN' in second string
mov dptr,#date_tab
con_version_more:
mov r0,#disp_buf
mov r2,#10 ;10 bytes in 'date' string
lcall rewr_from_rom
mov r2,#10 ;4 bytes in object number
mov r4,#6 ;offset in string
lcall send_part ;real time display
jb lcd_line_bit,delay_disp_version
setb lcd_line_bit
mov dptr,#time_tab
sjmp con_version_more

restart_system:
mov dptr,#restart_sys_lab
lcall update_display
mov beep_cnt,#250 ;beep length
%beep_start
mov m_tim_long,#15 ;1.5 sec. wait for display
mov a,#0
cjne a,m_tim_long,$
mov consol_cmd,#6 ;reset all system
lcall push_to_rs
jnb reset_flag,$ ;wait for master reset
mov ie,#0
ljmp 0

disp_sys_var:
mov dptr,#init_var_lab
lcall update_display
clr lcd_line_bit ;first string
mov dptr,#var_area
sys_var_str:
mov r0,#temp_buf
mov r2,#2
lcall rewr_from_ram
mov r0,#temp_buf
mov r1,#disp_buf
lcall conv_bin_asc
lcall conv_bin_asc
mov r2,#4 ;4 bytes in object number
mov r4,#12 ;offset in string
lcall send_part ;real time display
jb lcd_line_bit,exit_sys_var
setb lcd_line_bit
mov dptr,#var_area+3
sjmp sys_var_str
exit_sys_var:
ret

disp_phone_var:
mov dptr,#init_phone_lab
lcall update_display
setb lcd_line_bit ;second string
mov dptr,#var_area+19
mov r0,#temp_buf
mov r2,#6
lcall rewr_from_ram
mov r0,#temp_buf+1 ;without '+7'
mov r1,#disp_buf+1
mov r2,#5
conv_ph_numb:
lcall conv_bin_asc
djnz r2,conv_ph_numb
mov r1,#disp_buf ;sours_data
mov @r1,#'8'
mov r2,#11 ;11 bytes in object number
mov r4,#4 ;offset in string
lcall send_part ;alarm phone display
ret

;************ user view mode
user_view_mode:
setb tim_exit_en
clr main_mode_flag
mov dptr,#user_work_page
lcall read_all_disp
mov dptr,#inp_help_lab+16
setb lcd_line_bit ;second string
lcall send_lable ;display 'HELP' in second string
disp_view_sms:
mov dptr,#sms_incom_lab
clr lcd_line_bit ;first string
lcall send_lable
wait_view_sms:
lcall wait_push_button
jb up_rdy,disp_view_register
jb down_rdy,disp_view_register
jnb dies_rdy,wait_view_sms
ljmp sms_view_mode

disp_view_register:
mov dptr,#event_incom_lab
clr lcd_line_bit ;first string
lcall send_lable
wait_view_register:
lcall wait_push_button
jb up_rdy,select_time_corr
jb down_rdy,select_time_corr
jnb dies_rdy,wait_view_register
ljmp event_view_mode

select_time_corr:
mov dptr,#time_corr_lab
clr lcd_line_bit ;first string
lcall send_lable
wait_time_corr:
lcall wait_push_button
jb up_rdy,disp_exit_view
jb down_rdy,disp_exit_view
jnb dies_rdy,wait_time_corr
ljmp corr_time_mode

disp_exit_view:
mov dptr,#main_exit_lab
clr lcd_line_bit ;first string
lcall send_lable
wait_exit_view:
lcall wait_push_button
jb up_rdy,disp_view_sms
jb down_rdy,disp_view_sms
jnb dies_rdy,wait_exit_view
ljmp exit_to_main

sms_view_mode:
clr empty_flag
mov loop_cnt,#0
update_sms:
mov a,loop_cnt
lcall make_sms_data ;create buffer with sms data
lcall disp_sms_data
wait_modify_sms:
lcall wait_push_button
jb up_rdy,disp_sms_up
jb down_rdy,disp_sms_down
sjmp wait_modify_sms
disp_sms_down:
dec loop_cnt
anl loop_cnt,#00000111b
sjmp update_sms

disp_sms_up:
inc loop_cnt
anl loop_cnt,#00000111b
sjmp update_sms

corr_time_mode:
mov dptr,#time_set_lab
lcall update_display
wait_time_sel:
lcall wait_push_button
cjne a,#3,$+3
jnc wait_time_sel
jz wait_time_sel
rrc a
cpl c
mov time_corr_bit,c
ljmp exit_to_main

event_view_mode:
clr empty_flag
mov loop_cnt,#0
update_event:
mov a,loop_cnt
lcall make_event_data ;create buffer with event and help buffer
lcall disp_next_event
wait_next_event:
lcall wait_push_button
jb up_rdy,disp_event_up
jb down_rdy,disp_event_down
sjmp wait_next_event
disp_event_down:
dec loop_cnt
anl loop_cnt,#00011111b
sjmp update_event

disp_event_up:
inc loop_cnt
anl loop_cnt,#00011111b
sjmp update_event

make_sms_data:
mov dptr,#sem_sms_page
inc a
mov b,#32
mul ab
mov b,a
mov a,inc_rec_pnt
clr c
subb a,b
mov dpl,a
mov r0,#temp_buf
mov r2,#32
lcall rewr_from_ram
dec dpl
mov a,#0
movx @dptr,a ;reset unvisible flag
ret

make_event_data:
mov dptr,#register_page
inc a
mov b,#4
mul ab
mov b,a
mov a,push_disp_pnt
clr c
subb a,b
mov dpl,a
mov r0,#temp_buf
mov r2,#4
lcall rewr_from_ram
ret

;************ direct call mode
direct_call_mode:
setb tim_exit_en
clr main_mode_flag
mov dptr,#user_work_page
lcall read_all_disp
mov dptr,#user_call_lab
lcall update_display
wait_call_sel:
lcall wait_push_button ;wait for mode selected or esc.
jnb dies_rdy,wait_call_sel
mov dptr,#inp_help_lab
setb lcd_line_bit ;second string
lcall send_lable ;display 'HELP' in second string
start_ph_disp:
mov loop_cnt,#0 ;init. user phone index
mov a,loop_cnt
lcall get_ph_pointer
lcall updx_display
wait_next_ph:
lcall wait_push_button ;wait for user phone selected or esc.
jb dies_rdy,transfer_user_call
jb up_rdy,next_phone_up
jb down_rdy,next_phone_down
sjmp wait_next_ph

next_phone_down:
dec loop_cnt
dec loop_cnt
next_phone_up:
inc loop_cnt ;next user phone index
mov a,loop_cnt
cjne a,#8,$+3
jc $+4
sjmp start_ph_disp
lcall get_ph_pointer
movx a,@dptr
cjne a,#0ffh,$+5
sjmp start_ph_disp
cjne a,#'/',$+5
sjmp start_ph_disp
lcall updx_display
sjmp wait_next_ph

transfer_user_call:
mov consol_cmd,#3 ;set 'user phone ready' in status byte
mov con_data_1,loop_cnt ;set index of user phone
lcall push_to_rs
mov dptr,#connect_lab
lcall update_display
mov m_tim_long,#40 ;delay 4.0 sec.
mov a,#0
cjne a,m_tim_long,$ ;wait for talk_bit updated
ljmp test_ent_exit

;************ transfer sms mode
transfer_sms_mode:
setb tim_exit_en
clr main_mode_flag
mov dptr,#user_work_page
lcall read_all_disp
mov dptr,#user_sms_lab
lcall update_display
wait_transf_sel:
lcall wait_push_button ;wait for mode selected or esc.
jnb dies_rdy,wait_transf_sel
mov dptr,#inp_help_lab
setb lcd_line_bit ;second string
lcall send_lable ;display 'HELP' in second string
start_sms_disp:
mov loop_cnt,#0 ;init. user phone index
transf_sms_direct:
mov a,loop_cnt
lcall get_sms_pointer
lcall updx_display
wait_next_sms:
lcall wait_push_button ;wait for user phone selected or esc.
jb dies_rdy,transfer_user_sms
jb up_rdy,next_sms_up
jb down_rdy,next_sms_down
sjmp wait_next_sms

next_sms_down:
dec loop_cnt
dec loop_cnt
next_sms_up:
inc loop_cnt ;next user phone index
mov a,loop_cnt
cjne a,#16,$+3
jc $+4
sjmp start_sms_disp
lcall get_sms_pointer
movx a,@dptr
cjne a,#0ffh,$+5
sjmp start_sms_disp
cjne a,#'/',$+5
sjmp start_sms_disp

lcall updx_display
sjmp wait_next_sms

transfer_user_sms:
mov consol_cmd,#4 ;set 'user sms ready' in status byte
mov con_data_1,loop_cnt ;set index of user sms
lcall push_to_rs
mov dptr,#tr_sms_lable
lcall update_display
mov dptr,#user_work_page
lcall read_all_disp
mov dptr,#user_work_page+32
lcall read_all_disp
setb sound_long
mov sound_delay,#17 ;sound delay
mov sound_pause,#20 ;sound pause
wait_transfer_sound:
lcall sound_proc
mov a,sound_pause
cjne a,#2,wait_transfer_sound
clr sound_long
ljmp exit_to_main
;****************************

get_ph_pointer:
mov dptr,#semantic_area+256*4
mov b,#16
sjmp get_dptr_pnt
get_sms_pointer:
mov dptr,#semantic_area
mov b,#32
get_dptr_pnt:
mul ab
add a,dpl
mov dpl,a
mov a,b
addc a,dph
mov dph,a
ret

restore_display:
clr lcd_line_bit ;first string
lcall updx_disp_str
setb lcd_line_bit ;second string
lcall updx_disp_str
ret

updx_display:
clr lcd_line_bit ;first string
lcall updx_disp_str
ret
setb lcd_line_bit ;second string
lcall updx_disp_str
ret

updx_disp_str:
mov r0,#disp_buf ;taget buffer
mov r2,#16 ;bytes to rewrite
lcall rewr_from_ram ;pop next register string
lcall send_str ;send string
ret

ring_work:
mov sp,#stack_pointer ;restore stack
mov light_cnt,#30
clr lcd_light ;light on
clr main_mode_flag
setb sound_long
mov sound_delay,#20 ;sound delay
mov dptr,#ring_lable
lcall update_display
wait_user_ack:
lcall sound_proc
jnb ring_bit,exit_without_hook
test_ent_call:
jnb key_code_rdy,wait_user_ack
clr key_code_rdy
mov a,#cod_dies
cjne a,key_code_buf,wait_user_ack
mov consol_cmd,#1 ;hook 'ON' status
lcall push_to_rs
clr sound_long
mov dptr,#connect_lab
lcall update_display
mov m_tim_long,#40 ;delay 4.0 sec.
mov a,#0
cjne a,m_tim_long,$ ;wait for talk_bit updated
test_ent_exit:
jnb talk_bit,disconnect_line
jnb key_code_rdy,test_ent_exit
clr key_code_rdy
mov a,#cod_star
cjne a,key_code_buf,test_ent_exit
disconnect_line:
mov consol_cmd,#2 ;hook 'OFF' status
lcall push_to_rs
mov consol_cmd,#2 ;hook 'OFF' status
lcall push_to_rs
mov consol_cmd,#2 ;hook 'OFF' status
lcall push_to_rs
mov dptr,#disconnect_lab
lcall update_display
sjmp exit_ring_work
exit_without_hook:
mov dptr,#ring_alt_lable
lcall update_display
exit_ring_work:
mov dptr,#user_work_page
lcall read_all_disp ;store current display data
mov dptr,#user_work_page+32
lcall read_all_disp ;store current display data
clr sound_long
setb main_mode_flag
clr tim_exit_en
mov m_tim_long,#15
mov a,#0
cjne a,m_tim_long,$ ;wait for display
ljmp main_loop

sound_proc:
jnb sound_long,exit_sound_proc
jnb msec_bit,exit_sound_proc
clr msec_bit
djnz sound_delay,sound_more
mov sound_delay,#1
djnz sound_pause,exit_sound_proc
mov sound_pause,#10
mov sound_delay,#20
sjmp exit_sound_proc
sound_more:
mov beep_cnt,#43
%beep_start
exit_sound_proc:
ret

wait_push_button:
jnb reset_flag,$+6
ljmp 0
jnb tim_exit_en,work_register
mov a,tim_exit_cnt
cjne a,#1,$+6
ljmp exit_to_main ;direct exit to main loop
work_register:
lcall display_register ;display data from main controller
lcall update_time
lcall det_unvis_mess ;detect unvisible incom_sms
jnb ring_bit,test_keyboard
;!!!
mov m_tim_long,#4 ;delay 400 msec.
mov a,#0
cjne a,m_tim_long,$ ;wait for ring_bit valid
jnb ring_bit,test_keyboard
ljmp ring_work ;direct jump to ring mode
test_keyboard:
jnb key_code_rdy,wait_push_button
verify_push_button:
mov tim_exit_cnt,#200 ;20 sec timout
anl key_flags,#11100000b;clear key flags
mov a,key_code_buf
cjne a,#cod_star,test_up_key
setb star_rdy
ljmp exit_to_main ;direct exit to main loop
test_up_key:
cjne a,#cod_up,test_down_key
setb up_rdy
sjmp exit_push_button
test_down_key:
cjne a,#cod_down,test_ent_key
setb down_rdy
sjmp exit_push_button
test_ent_key:
cjne a,#cod_dies,exit_push_button
setb dies_rdy
exit_push_button:
ret

display_register:
mov a,disp_timout
cjne a,#1,exit_display_reg
jnb main_mode_flag,exit_display_reg
mov a,push_disp_pnt
xrl a,pop_disp_pnt ;verify new display message
jz exit_display_reg ;jump,if buffer to display empty
lcall pop_register ;read next register string to temp_buf
mov r0,#temp_buf
mov a,@r0
xrl a,#8 ;verify 'next transfer' event
jz exit_display_reg
mov a,@r0
xrl a,#16 ;verify 'new semantic sms' event
jz exit_display_reg
mov light_cnt,#30
clr lcd_light ;light on
lcall sound_event ;create sound
lcall disp_next_event ;display register event
mov disp_timout,b ;restore display timout
mov dptr,#user_work_page+32
lcall read_all_disp ;store current display data
exit_display_reg:
ret

sound_event:
mov r0,#temp_buf
mov a,@r0
mov dptr,#sound_tab
movc a,@a+dptr
jz exit_sound_event
mov beep_cnt,a
%beep_start
exit_sound_event:
ret

sound_tab:
db 0 ;0 event 'register data empty'
db 100 ;1 event 'init from center'
db 100 ;2 event 'write mask from center'
db 100 ;3 event 'read mask by center'
db 100 ;4 event 'read X_Y by center'
db 100 ;5 event 'output X on'
db 100 ;6 event 'output X off'
db 0 ;7 event 'work with PC'
db 33 ;8 event 'transfer data to center'
db 250 ;9 event 'alarm X input'
db 0 ;10 event 'coord ----- -----'
db 0 ;11 event 'gps not correct'
db 200 ;12 event 'road control fault'
db 100 ;13 event 'time control ok'
db 200 ;14 event 'time control fault'
db 200 ;15 event 'user sms from center'


disp_sms_data: ;display semantic sms
mov r0,#temp_buf
mov a,@r0
xrl a,#0ffh
jz disp_empty_sem
lcall disp_incom_sms ;display from temp_buf
sjmp exit_disp_sem
disp_empty_sem:
mov dptr,#empty_reg_lab ;display empty if event not found
lcall update_display
setb empty_flag
exit_disp_sem:
ret

disp_next_event: ;display register event
mov r0,#temp_buf
mov a,@r0
cjne a,#0ffh,disp_event_more
mov dptr,#empty_reg_lab ;display empty if event not found
lcall update_display
setb empty_flag
mov b,#7 ;timout untill next display
ljmp exit_disp_event
disp_event_more:
push acc ;store event type
inc r0
mov b,#32
mul ab
mov dptr,#register_lab
add a,dpl
mov dpl,a
mov a,b
addc a,dph
mov dph,a
lcall update_display
clr lcd_line_bit ;first string
mov r4,#0 ;offset in string
lcall time_disp
pop acc ;restore event type

cjne a,#9,test_more_event
;--- insert alarm number
mov r1,#temp_buf+3 ;alarm number hear
mov a,#30h
add a,@r1
mov disp_buf,a
setb lcd_line_bit ;second string
mov r4,#11 ;offset in string
mov r2,#1 ;1 bytes in part
lcall send_part ;send alarm number
mov b,#7 ;timout untill next display
sjmp exit_disp_event
test_more_event:
mov b,#7 ;timout untill next display
exit_disp_event:
ret

disp_incom_sms:
mov r0,#temp_buf+30
mov @r0,#' '
inc r0
mov @r0,#' '
mov r0,#temp_buf
mov r1,#disp_buf
mov r2,#16
lcall transfer_r0_r1
clr lcd_line_bit ;first string
lcall send_str ;send first string

mov r0,#temp_buf+16
mov r1,#disp_buf
mov r2,#16 ;bytes to rewrite
lcall transfer_r0_r1 ;pop next register string
setb lcd_line_bit ;second string
lcall send_str ;send second string
ret

;!!!
time_disp:
mov r0,#temp_buf+1 ;sours bcd
alt_time_disp:
mov r1,#disp_buf ;taget display
lcall correct_time ;correct sattelit time (+3/+4 hour)
lcall conv_time_asc ;insert hour
mov @r1,#':' ;insert terminator
jb gps_bit,convert_min
;--- blink
mov a,secund_cnt
cjne a,#3,$+3
jnc convert_min
;---
mov @r1,#' ' ;insert terminator
convert_min:
inc r1
lcall conv_time_asc ;insert min.
mov @r1,#' '
mov r2,#6 ;6 bytes in time part
mov r4,#0 ;offset in string
lcall send_part ;real time display
ret

correct_time:
mov a,@r0 ;read hour
swap a
anl a,#00001111b
mov b,#10
mul ab
mov b,a ;store high part of hour bin
mov a,@r0 ;read hour
anl a,#00001111b
add a,b ;acc=hour binary
mov b,#4
jb time_corr_bit,$+6
mov b,#3
add a,b
cjne a,#24,$+5
mov a,#0
cjne a,#25,$+5
mov a,#1
cjne a,#26,$+5
mov a,#2
cjne a,#27,$+5
mov a,#3
mov b,#10
div ab
swap a
orl a,b
mov @r0,a
ret

conv_asc_rs:
mov dptr,#rs_rec_page
mov r0,#temp_buf
mov r2,#32
lcall rewr_from_ram
ret

init_semantic: ;init semantic ram
clr ie.4 ;close rs interrupt
mov dptr,#semantic_area
wait_sem_byte:
lcall rec_rs_byte
movx @dptr,a
inc dptr
mov a,dph
cjne a,#high(semantic_area+256*10),wait_sem_byte
exit_init_sem:
setb ie.4 ;rs interrupt open
ret

display_init:
lcall lcd_ini ;init lcd display
lcall lcd_gen_ini ;init lcd display
lcall clr_display
mov dptr,#main_lable ;'GPS navigator' lable
lcall update_display
ret

rewr_to_ram: ;store data in external ram
mov a,@r0
movx @dptr,a
inc r0
inc dpl
djnz r2,rewr_to_ram
ret

rewr_from_ram: ;restore data from external ram
movx a,@dptr
mov @r0,a
inc r0
inc dpl
djnz r2,rewr_from_ram
ret

rewr_from_rom: ;restore data from code memory
mov a,#0
movc a,@a+dptr
mov @r0,a
inc r0
inc dptr
djnz r2,rewr_from_rom
ret

ram_to_ram: ;transfer data @dptr_1 -> @dptr_2
%dptr_1
movx a,@dptr
inc dptr
%dptr_2
movx @dptr,a
inc dptr
djnz r2,ram_to_ram
%dptr_1
ret

fill_ext_ram: ;fill external ram with acc
movx @dptr,a
inc dptr
djnz r2,fill_ext_ram
ret

clear_push_rs_page:
mov dptr,#push_rs_page
sjmp clear_buf
clear_tr_page:
mov dptr,#rs_tr_page
sjmp clear_buf
clear_rec_page: ;clear ram page to receive
mov dptr,#rs_rec_page
clear_buf:
mov r2,#0 ;256 bytes to fill
mov a,#0ffh
lcall fill_ext_ram ;clear page
ret

clear_register_page:
mov dptr,#register_page
mov r2,#0 ;256 bytes to fill
mov a,#0ffh
lcall fill_ext_ram ;clear page
mov dptr,#register_page
mov a,#0
movx @dptr,a
inc dptr
movx @dptr,a
inc dptr
movx @dptr,a
inc dptr
movx @dptr,a
inc dptr
mov push_disp_pnt,#4
ret

clear_incom_sms_page:
;--- create data to fill
mov r0,#temp_buf
mov r2,#30
mov a,#0ffh
lcall fill_acc ;fill @r0 with acc
mov @r0,#0
inc r0
mov @r0,#0
;--- execute fill
mov dptr,#sem_sms_page
mov r3,#8 ;stinges to fill
clear_sms_string:
mov r0,#temp_buf
mov r2,#32
lcall rewr_to_ram
djnz r3,clear_sms_string
ret

out_rs_byte:
mov sbuf,a
jnb ti,$
clr ti
ret

out_rs_block:
clr ie.4
out_next_rsbyte:
mov a,@r0
lcall out_rs_byte
inc r0
djnz r2,out_next_rsbyte
setb ie.4
ret

rec_rs_byte:
jnb ri,$
mov a,sbuf
clr ri
ret

set_sys_reg:
push dph
push dpl
push acc
mov a,sys_reg_byte
mov dptr,#sys_addr
movx @dptr,a
; mov p2,sys_reg_byte
; clr reg_clock
; setb reg_clock
pop acc
pop dpl
pop dph
ret

led_cpl:
cpl led_bit
sjmp init_led
led_on:
clr led_bit
sjmp init_led
led_off:
setb led_bit
sjmp init_led
init_led:
lcall set_sys_reg
ret

transfer_r0_r1: ;transfer @r0 -> @r1
mov a,@r0
mov @r1,a
inc r0
inc r1
djnz r2,transfer_r0_r1
ret

init_ext_ram: ;fill RAM with 'b'
push r3b0 ;r2 = pages to fill
init_next_page:
mov r3,#0
init_ext_byte:
mov a,b
movx @dptr,a
inc dptr
djnz r3,init_ext_byte
djnz r2,init_next_page
pop r3b0
ret

conv_tab: ;convert 'FF'->0ffh,'3A'->3ah
db 0 ;return 00h 00h
db 1 ;return 01h 01h
db 2 ;return 02h 02h
db 3 ;return 03h 03h
db 4 ;return 04h 04h
db 5 ;return 05h 05h
db 6 ;return 06h 06h
db 7 ;return 07h 07h
db 8 ;return 08h 08h
db 9 ;return 09h 09h
db 0 ;return 00h 0ah
db 0 ;return 00h 0bh
db 0 ;return 00h 0ch
db 0 ;return 00h 0dh
db 0 ;return 00h 0eh
db 0 ;return 00h 0fh
db 0 ;return 00h 10h
db 0ah ;return 0ah 11h
db 0bh ;return 0bh 12h
db 0ch ;return 0ch 13h
db 0dh ;return 0dh 14h
db 0eh ;return 0eh 15h
db 0fh ;return 0fh 16h

pop_incom_sms:
mov dptr,#sem_sms_page
mov dpl,a ;dptr = sours register with sms book
push dpl
add a,#31
mov dpl,a
mov a,#0
movx @dptr,a ;clear unvis. flag
pop dpl
mov r0,#temp_buf ;taget buffer
mov r2,#32 ;bytes to pop
lcall rewr_from_ram ;pop next incom sms
ret

pop_register: ;pop message from register_page
mov dptr,#register_page
mov dpl,pop_disp_pnt ;dptr = register string to display
mov r0,#temp_buf ;taget buffer
mov r2,#4 ;bytes to rewrite
lcall rewr_from_ram ;pop next register string
mov a,pop_disp_pnt
add a,#4
mov pop_disp_pnt,a ;modify pop counter
ret

conv_bin_asc: ;convert 0feh -> 'FE',sours @r0,taget @r1
mov dptr,#asc_tab
mov a,@r0 ;read byte
swap a ;high nibble
anl a,#00001111b
movc a,@a+dptr ;get asc byte
mov @r1,a ;store asc byte
inc r1
mov a,@r0 ;read again
anl a,#00001111b ;low nibble
movc a,@a+dptr ;get asc byte
mov @r1,a ;store asc byte
inc r1
inc r0
ret

conv_time_asc: ;convert 0feh -> 'FE',sours @r0,taget @r1
mov dptr,#asc_tab
mov a,@r0 ;read byte
swap a ;high nibble
anl a,#00001111b
cjne a,#10,$+3
jc conv_time_high
mov a,#0
conv_time_high:
movc a,@a+dptr ;get asc byte
mov @r1,a ;store asc byte
inc r1
mov a,@r0 ;read again
anl a,#00001111b ;low nibble
cjne a,#10,$+3
jc conv_time_low
mov a,#0
conv_time_low:
movc a,@a+dptr ;get asc byte
mov @r1,a ;store asc byte
inc r1
inc r0
ret

asc_tab:
db '0123456789ABCDEF'

pack_rs_data:
mov dptr,#rs_rec_page ;consol address hear
movx a,@dptr
jz $+5
ljmp exit_pack_data ;exit if address not valid
inc dptr
movx a,@dptr ;read command
test_register_pack:
cjne a,#0,test_status_pack
mov dptr,#rs_rec_page+2 ;from this point register data begin
register_data_pack:
movx a,@dptr ;read register byte
push dph
push dpl
mov dph,#high(register_page)
mov dpl,push_disp_pnt ;dptr = taget addr. to store
movx @dptr,a ;store semantic byte
inc push_disp_pnt
pop dpl
pop dph
inc dptr
mov a,dpl
cjne a,#low(rs_rec_page)+6,register_data_pack
sjmp send_cons_data
test_status_pack:
cjne a,#2,test_init_sem
mov dptr,#rs_rec_page+2
movx a,@dptr ;read master status byte
mov mast_status,a
mov dptr,#rs_rec_page+3
movx a,@dptr ;read hour byte
mov dptr,#user_work_page+128
movx @dptr,a ;store hour byte
mov dptr,#rs_rec_page+4
movx a,@dptr ;read min. byte
mov dptr,#user_work_page+129
movx @dptr,a ;store min. byte
sjmp send_cons_data
test_init_sem:
cjne a,#3,test_sys_reset
setb init_sem_bit
ljmp exit_pack_data
test_sys_reset:
cjne a,#4,test_incsms_pack
setb reset_flag ;reset indicator
sjmp send_cons_data
test_incsms_pack:
cjne a,#5,exit_pack_data
mov dptr,#rs_rec_page+32
mov a,#0ffh
movx @dptr,a
inc dptr
movx @dptr,a ;fill last 2 bytes with '0ffh'
mov dptr,#rs_rec_page+2 ;from this point semantic data begin
semantic_sms_pack:
movx a,@dptr ;read incom sms semantic byte
push dph
push dpl
mov dph,#high(sem_sms_page)
mov dpl,inc_rec_pnt ;dptr = taget addr. to store
movx @dptr,a ;store semantic byte
inc inc_rec_pnt
pop dpl
pop dph
inc dptr
mov a,dpl
cjne a,#low(rs_rec_page)+34,semantic_sms_pack
send_cons_data:
mov a,push_tr_pnt
xrl a,pop_tr_pnt
jz send_sp_stat
pop_next_byte:
mov dph,#high(push_rs_page)
mov dpl,pop_tr_pnt
movx a,@dptr
mov dph,#high(rs_tr_page)
mov dpl,pop_tr_pnt
anl dpl,#00000011b
movx @dptr,a
inc pop_tr_pnt
mov a,pop_tr_pnt
anl a,#00000011b
jnz pop_next_byte
sjmp transfer_begin
send_sp_stat:
mov dptr,#rs_tr_page
mov a,#0
movx @dptr,a ;update status
inc dptr
mov a,#0ffh
movx @dptr,a ;don't care byte
inc dptr
movx @dptr,a ;don't care byte
inc dptr
movx @dptr,a ;check
transfer_begin:
mov rs_tr_pnt,#0
mov rs_tr_cnt,#9
clr tr_sync_flag
mov sbuf,#'$' ;start header
exit_pack_data:
ret

det_unvis_mess: ;detect unvisible incom_sms
jnb main_mode_flag,exit_det_unvis
setb unvis_flag
mov r7,#0
det_unvis_string:
mov dptr,#unvis_flag_tab
mov a,r7
movc a,@a+dptr
mov dph,#high(sem_sms_page)
mov dpl,a
movx a,@dptr
jnz unvis_sound_proc
inc r7
cjne r7,#8,det_unvis_string
clr unvis_flag
sjmp test_restore_disp
unvis_sound_proc:
jnb unvis_sound,test_restore_disp
clr unvis_sound
mov beep_cnt,#27
%beep_start
mov light_cnt,#30
clr lcd_light ;light on
setb secondary_disp
mov dptr,#unvis_sms_lab
lcall update_display
sjmp exit_det_unvis
test_restore_disp:
jnb secondary_disp,exit_det_unvis
mov a,sms_snd_cnt
xrl a,#17
jnz exit_det_unvis
mov dptr,#user_work_page+32
lcall restore_display ;restore previos register data
clr secondary_disp
exit_det_unvis:
ret

;restore_first_disp:
; jnb main_mode_flag,exit_restore_first
; jnb secondary_disp,exit_restore_first
; mov a,sms_snd_cnt
; xrl a,#17
; jnz exit_restore_first
; mov dptr,#user_work_page
; lcall restore_display
; clr secondary_disp
;exit_restore_first:
; ret

unvis_flag_tab:
db 32*0+31
db 32*1+31
db 32*2+31
db 32*3+31
db 32*4+31
db 32*5+31
db 32*6+31
db 32*7+31

push_to_rs: ;push data to master transfer
mov dph,#high(push_rs_page)
mov dpl,push_tr_pnt
mov a,consol_cmd
movx @dptr,a ;update status
inc dpl
mov a,con_data_1
movx @dptr,a ;don't care byte
inc dpl
mov a,con_data_2
movx @dptr,a ;don't care byte
inc dpl
mov a,#0ffh
movx @dptr,a ;check
inc dpl
mov push_tr_pnt,dpl
ret

update_time:
jnb main_mode_flag,exit_time_upd
jb secondary_disp,exit_time_upd
jnb time_upd_bit,exit_time_upd
clr time_upd_bit
mov dptr,#user_work_page+128
mov r0,#temp_buf+1 ;taget buffer to bcd time
mov r2,#2
lcall rewr_from_ram
clr lcd_line_bit ;first string
lcall time_disp
exit_time_upd:
ret

out_sem_ram: ;init semantic ram
mov dptr,#semantic_area
out_sem_byte:
movx a,@dptr
lcall out_rs_byte
inc dptr
mov a,dph
cjne a,#high(semantic_area+256*10),out_sem_byte
ret

date_tab:
$include(date.dat)
time_tab:
$include(time.dat)

main_ver_lab:
db 'MAST. '
cons_ver_lab:
db 'CONS. '

register_lab equ 1000h

inp_help_lab equ 1300h
main_lable equ 1330h

init_lable equ main_lable+32
tr_sms_lable equ init_lable+32
user_call_lab equ tr_sms_lable+32
user_sms_lab equ user_call_lab+32
connect_lab equ user_sms_lab+32
disconnect_lab equ connect_lab+32
ring_lable equ disconnect_lab+32
ring_alt_lable equ ring_lable+32
reg_view_lab equ ring_alt_lable+32
sms_incom_lab equ reg_view_lab+32
event_incom_lab equ sms_incom_lab+16
main_exit_lab equ event_incom_lab+16
cass_fault_lab equ main_exit_lab+16 ;???
cass_ins_lab equ cass_fault_lab+32 ;???
empty_reg_lab equ cass_ins_lab+32
init_ok_lable equ empty_reg_lab+32
time_corr_lab equ init_ok_lable+32
time_set_lab equ time_corr_lab+16
init_var_lab equ time_set_lab+32
init_phone_lab equ init_var_lab+32
test_mode_lab equ init_phone_lab+32
restart_sys_lab equ test_mode_lab+32
unvis_sms_lab equ restart_sys_lab+32

;cg_tab equ 1f00h

$include(rus_lab.asm)

end

Составить ответ  |||  Конференция  |||  Архив

Ответы


Отправка ответа
Имя (обязательно): 
Пароль: 
E-mail: 

Тема (обязательно):
Сообщение:

Ссылка на URL: 
URL изображения: 


Rambler's Top100 Рейтинг@Mail.ru
Перейти к списку ответов  |||  Конференция  |||  Архив  |||  Главная страница  |||  Содержание