📄 telephone.asm
字号:
;/*; telephone.asm; cpu = lpc936; Fosc = 11.0592Mhz; ; simulate telephone block:; function:; 1) send & receive dtmf; 2) monitor switch; 3) simulate bus; 4) sample; 5) uart; 6) hook operate; 7) scan ring; 8) message manage & status report; ; redefine port function:; Bit 0 1 2 3 4 5 6 7; P0 - Md0 Md1 Md2 Md3 Rs0 Wr Rd; P1 Tx Rx Rts Cts Dsr - Dtr -; P2 Tout - Mon R/To Cs Irq HK R/Rg; P3 - -; Describe:; Simulate Bus Pin define: Md0~Md3(Data in/out) Rs0(Address out) Wr Rd Cs Irq; Uart Function Pin define: Tx(in) Rx(out) Rts(out) Cts(in) Dsr(in) Dtr(out); Telephone Interface Pin define: Tout(AD input) Mon(monitor Switch output); R/To(Tone Signal input=AD input) ; HK(hook Switch output); R/Rg(Ring Status input); ; Copyright For MaRF;*/$INCLUDE (REG936.INC);//define constantSAMPLE_SIZE_MASK EQU 7Fh ;sample buffer size = 128 bytePHONE_DIAL_SIZE_MASK EQU 3Fh ;size = 64 bytePHONE_DIAL_SIZE EQU 40hUART_TX_SIZE EQU 80h ;UART_TX_SIZE_MASK EQU 7Fh ;UART_RX_SIZE EQU 40h ;UART_RX_SIZE_MASK EQU 3Fh ;UART_RX_HIGH_MASK EQU 0E0h ;UART_RX_LOW_MASK EQU 0F0h ;MSG_FINISH_DIAL EQU 40hMSG_START_SAMPLE EQU 30hMSG_STOP_SAMPLE EQU 31hMSG_SAMPLE_DATA EQU 32hMSG_SET_SAMPLE_INTERVAL EQU 33hMSG_START_DIAL EQU 34hMSG_STOP_DIAL EQU 35hMSG_SET_DIAL_PARAMETER EQU 36hMSG_SET_HOLD_PERIOD EQU 37hMSG_SET_HOOK_PERIOD EQU 38hMSG_HOOK EQU 39hMSG_SND_DTMF EQU 3ahMSG_STOP_DTMF EQU 3bhMSG_MONITOR EQU 3ch MSG_RING EQU 3dhMSG_SYSTEM_TIMER EQU 3ehMSG_ERROR EQU 45hMSG_BUSY EQU 42hMSG_SUCCESS EQU 53hCRC_INITIAL EQU 64hMSG_RX_SIZE_MASK EQU 1FhMSG_TX_SIZE_MASK EQU 1Fh;//Reg Default Value ;bit0 bit7TMOD_VALUE EQU 01h ;T0M0 T0M1 T0C/T T0GATE T1M0 T1M1 T1C/T T1GATETAMOD_VALUE EQU 00h ;T0M2 - - - T1M2 - - -TLODER EQU 93FFh ;(FFFF - TLODER)*(2/Fosc) = Timer(10ms)TENABLE0 EQU 02h ;IEN0.0TPRIORITYH EQU 00h ;IP0H.1TPRIORITYL EQU 00h ;IP0L.1UTXENABLE EQU 40h ;IEN1.6URXENABLE EQU 10h ;IEN0.4UTXPRIORITYH EQU 00h ;IP1H.0UTXPRIORITYL EQU 00h ;IP1L.0URXPRIORITYH EQU 00h ;IP0H.4URXPRIORITYL EQU 00h ;IP0L.4SSTAT_VALUE EQU 60hSCON_VALUE EQU 50h;//Reg Function redefinephone_dial_counter data 08hsample_head data 09hsample_tail data 0ahsample_counter data 0bhsample_interval data 0chsample_length data 0dhsample_save data 0ehbus_reg data 0fhuart_tx_head data 10huart_tx_tail data 11huart_tx_length data 12huart_rx_head data 13huart_rx_tail data 14huart_rx_length data 15hdtmf_on_period data 16hdtmf_off_period data 17hhook_updown_period data 18hhold_period data 19hphone_dial_head data 1ahphone_dial_tail data 1bhphone_dial_length data 1chphone_dial_temp data 1dhtone_check_period data 1ehmute_check_period data 1fhtime_stamp data 28hmsg_rece_index data 2chmsg_rece_length data 2dhmsg_send_index data 2ehmsg_send_length data 2fh;//bit function redefinesample_start_flag bit 00huart_tx_running_flag bit 01huart_enable_term bit 02huart_enable_flow bit 03huart_opened bit 04hphone_dial_start bit 05hdial_return_ok_flag bit 06hphone_dial_code_flag bit 07hphone_tone_check_enable bit 08hphone_tone_check_flag bit 09hdsr_save_status bit 0ahdsr_return_ok_flag bit 0bhring_save_status bit 0chring_return_ok_flag bit 0dhmsg_rece_ready_flag bit 0ehmsg_send_ready_flag bit 0fhsample_return_ok_flag bit 10htone_return_ok_flag bit 11h;//extern ram redefinesample_buffer xdata 0000huart_tx_buffer xdata 0080huart_rx_buffer xdata 00C0hphone_dial_buffer xdata 0100hmsg_rece_buffer xdata 0140hmsg_send_buffer xdata 0160hdsr_timer_stamp_buffer xdata 0180hring_timer_stamp_buffer xdata 0188hdial_timer_stamp_buffer xdata 0190hsample_timer_stamp_buffer xdata 0198htimer_stamp_buffer xdata 01a0htone_timer_stamp_buffer xdata 01a8h;//pin redefinePHONE_SAMPLE bit p2.3PHONE_HOOK bit p2.6PHONE_RING bit p2.7PHONE_MONITOR bit p2.2UART_RTS bit p1.2UART_CTS bit p1.3UART_DTR bit p1.6UART_DSR bit p1.4BUS_CS bit p2.4BUS_WR bit p0.6BUS_RD bit p0.7BUS_RS0 bit p0.5BUS_IRQ bit p2.5BUS_MD0 bit p0.1BUS_MD1 bit p0.2BUS_MD2 bit p0.3BUS_MD3 bit p0.4;//_main:mov SP,#80hmov PSW,#00hmov P0M1,#00hmov P0M2,#0FFhmov P1M1,#18h ; 00011000mov P1M2,#0E5h ; 11100101mov P2M1,#00hmov P2M2,#00hmov P3M1,#00hmov P3M2,#01hanl TRIM,#3Fhmov DIVM,#00hlcall _bus_initiallcall _package_initlcall _uart_initiallcall _phone_8889_initiallcall _sample_initlcall _dial_initlcall _timer_initiallcall phone_initclr Alcall _uart_opensetb EA;//主循环_main_cyc:lcall _package_readlcall _package_writelcall _uart_scanlcall _phone_diallcall _msg_proclcall _RING_STATUS_ALARMlcall _ring_alarm_return_timerlcall _DSR_STATUS_ALARMlcall _dsr_status_alarm_returnlcall _sample_start_returnlcall _tone_start_returnlcall _dial_stop_oklcall _SAMPLE_DATA_REBACKsjmp _main_cyc_package_init:clr msg_send_ready_flagmov msg_send_length,#00hmov msg_send_index,#00hclr msg_rece_ready_flagmov msg_rece_length,#00hmov msg_rece_index,#00hret;/-----------------------;;;10+20*m+(m+1)PC(UART_READ);/-----------------------_package_read:lcall _uart_read ;?2jnc _package_read_exit ;?2jnz $+6h ;?2setb msg_rece_ready_flag ;?1mov msg_rece_index,#00h ;?2ret ;?1push ACC ;?1mov DPTR,#msg_rece_buffer ;?2mov A,msg_rece_length ;?1add A,DPL ;?1mov DPL,A ;?1pop ACC ;?1movx @DPTR,A ;?2inc msg_rece_length ;?1anl msg_rece_length,#MSG_RX_SIZE_MASK ;?2sjmp _package_read ;2_package_read_exit:ret;/-------------------------;;;;17*n+11+n*PC(UART_WRITE),n表示写入多少个字符;/-------------------------_package_write:jb msg_send_ready_flag,$+4h ;2ret_package_write_cyc:mov A,msg_send_index ;1cjne A,msg_send_length,$+10h ;2 17*n+9+2mov msg_send_index,#00h ;2mov msg_send_length,#00h ;2clr msg_send_ready_flag ;1ret ;1mov DPTR,#msg_send_buffer ;2mov A,msg_send_index ;1add A,DPL ;1mov DPL,A ;1movx A,@DPTR ;2lcall _uart_write ;2jc $+3h ;2ret inc msg_send_index ;1sjmp _package_write_cyc ;2;//;//********************************CRC FUNCTION********************************CRC_TAB:DB 00h, 5eh, 0bch, 0e2h, 61h, 3fh, 0ddh, 83h DB 0c2h, 9ch, 7eh, 20h, 0a3h, 0fdh, 1fh, 41h DB 9dh, 0c3h, 21h, 7fh, 0fch, 0a2h, 40h, 1eh DB 5fh, 01h, 0e3h, 0bdh, 3eh, 60h, 82h, 0dch DB 23h, 7dh, 9fh, 0c1h, 42h, 1ch, 0feh, 0a0h DB 0e1h, 0bfh, 5dh, 03h, 80h, 0deh, 3ch, 62h DB 0beh, 0e0h, 02h, 5ch, 0dfh, 81h, 63h, 3dh DB 7ch, 22h, 0c0h, 9eh, 1dh, 43h, 0a1h, 0ffh DB 46h, 18h, 0fah, 0a4h, 27h, 79h, 9bh, 0c5h DB 84h, 0dah, 38h, 66h, 0e5h, 0bbh, 59h, 07h DB 0dbh, 85h, 67h, 39h, 0bah, 0e4h, 06h, 58h DB 19h, 47h, 0a5h, 0fbh, 78h, 26h, 0c4h, 9ah DB 65h, 3bh, 0d9h, 87h, 04h, 5ah, 0b8h, 0e6h DB 0a7h, 0f9h, 1bh, 45h, 0c6h, 98h, 7ah, 24h DB 0f8h, 0a6h, 44h, 1ah, 99h, 0c7h, 25h, 7bh DB 3ah, 64h, 86h, 0d8h, 5bh, 05h, 0e7h, 0b9h DB 8ch, 0d2h, 30h, 6eh, 0edh, 0b3h, 51h, 0fh DB 4eh, 10h, 0f2h, 0ach, 2fh, 71h, 93h, 0cdh DB 11h, 4fh, 0adh, 0f3h, 70h, 2eh, 0cch, 92h DB 0d3h, 8dh, 6fh, 31h, 0b2h, 0ech, 0eh, 50h DB 0afh, 0f1h, 13h, 4dh, 0ceh, 90h, 72h, 2ch DB 6dh, 33h, 0d1h, 8fh, 0ch, 52h, 0b0h, 0eeh DB 32h, 6ch, 8eh, 0d0h, 53h, 0dh, 0efh, 0b1h DB 0f0h, 0aeh, 4ch, 12h, 91h, 0cfh, 2dh, 73h DB 0cah, 94h, 76h, 28h, 0abh, 0f5h, 17h, 49h DB 08h, 56h, 0b4h, 0eah, 69h, 37h, 0d5h, 8bh DB 57h, 09h, 0ebh, 0b5h, 36h, 68h, 8ah, 0d4h DB 95h, 0cbh, 29h, 77h, 0f4h, 0aah, 48h, 16h DB 0e9h, 0b7h, 55h, 0bh, 88h, 0d6h, 34h, 6ah DB 2bh, 75h, 97h, 0c9h, 4ah, 14h, 0f6h, 0a8h DB 74h, 2ah, 0c8h, 96h, 15h, 4bh, 0a9h, 0f7h DB 0b6h, 0e8h, 0ah, 54h, 0d7h, 89h, 6bh, 35h_crc_calculate:xrl A,Bmov DPTR,#CRC_TABmovc A,@A+DPTRret;//********************************End Crc FUNCTION****************************;//*******************************UART FUNCTION***********************************;Uart_Baud_Tabl:DB 50h,0B0h,10h,70h,30h,0F0h, 70h,0F0h,0F0h,0F0h ;110592l;Uart_Baud_Tabh:DB 00h, 00h,01h,01h,02h, 02h, 04h, 08h, 11h, 23h ;110592hUart_Baud_Tabl:DB 58h,0C0h,29h,90h,61h, 31h,0D2h,0B4h, 78h, 00h ;120000lUart_Baud_Tabh:DB 00h, 00h,01h,01h,02h, 03h, 04h, 09h, 13h, 27h ;120000h;--------------------;;;--------------------_uart_initial:mov uart_tx_length,#00hmov uart_tx_head,#00hmov uart_tx_tail,#00hmov uart_rx_length,#00hmov uart_rx_head,#00hmov uart_rx_tail,#00hclr uart_openedclr uart_tx_running_flagclr uart_enable_termclr uart_enable_flowsetb UART_DTRsetb UART_RTSmov SSTAT,#SSTAT_VALUEmov SCON,#SCON_VALUEorl IP1H,#UTXPRIORITYHorl IP1,#UTXPRIORITYLorl IP0H,#URXPRIORITYHorl IP0,#URXPRIORITYLret;--------------------;Function Open Uart;parameter ACC=baudrate;return NULL;--------------------_uart_open:anl A,#0fhpush ACCmov BRGCON,#02hmov DPTR,#Uart_Baud_Tablmovc A,@A+DPTRmov BRGR0,Apop ACCmov DPTR,#Uart_Baud_Tabhmovc A,@A+DPTRmov BRGR1,Amov BRGCON,#03hclr uart_tx_running_flagsetb uart_openedmov uart_rx_length,#00hmov uart_rx_head,#00hmov uart_rx_tail,#00horl IEN1,#UTXENABLEorl IEN0,#URXENABLEclr UART_RTSclr UART_DTRret;--------------------;;;--------------------_uart_close:setb UART_RTSsetb UART_DTRmov A,#UTXENABLEcpl Aanl IEN1,#UTXENABLEmov A,#URXENABLEcpl Aanl IEN0,#URXENABLEmov uart_tx_head,#00hmov uart_tx_tail,#00hmov uart_tx_length,#00hclr uart_tx_running_flagclr uart_openedclr uart_enable_flowclr uart_enable_termmov BRGCON,#02hret;--------------------;;18;--------------------_uart_write:push ACCmov A,uart_tx_length cjne A,#UART_TX_SIZE,$+7hpop ACCclr Cretmov DPTR,#uart_tx_buffer mov A,uart_tx_tail add A,DPL mov DPL,A pop ACC movx @DPTR,A inc uart_tx_tail anl uart_tx_tail,#UART_TX_SIZE_MASK inc uart_tx_lengthsetb Cret;--------------------;;15;--------------------_uart_read:mov A,uart_rx_lengthjnz $+4hclr Cretmov DPTR,#uart_rx_buffermov A,uart_rx_headadd A,DPL mov DPL,A movx A,@DPTR inc uart_rx_head anl uart_rx_head,#UART_RX_SIZE_MASK dec uart_rx_lengthsetb Cret;--------------------;;38;--------------------_uart_scan:jnb uart_enable_flow,_uart_scan_bursttxjnb UART_RTS,_uart_scan_bursttxmov A,uart_rx_lengthanl A,#UART_RX_LOW_MASKjnz _uart_scan_bursttxclr UART_RTS_uart_scan_bursttx:jnb uart_opened,_uart_scan_exitjb uart_tx_running_flag,_uart_scan_exitjnb uart_enable_term,$+6hjb UART_DSR,_uart_scan_exitjnb uart_enable_flow,$+6hjb UART_CTS,_uart_scan_exitmov A,uart_tx_lengthjnz $+4hsjmp _uart_scan_exitmov DPTR,#uart_tx_buffermov A,uart_tx_headadd A,DPLmov DPL,Amovx A,@DPTRsetb uart_tx_running_flagmov SBUF,Ainc uart_tx_headanl uart_tx_head,#UART_TX_SIZE_MASKdec uart_tx_length_uart_scan_exit:ret;--------------------;;35;--------------------_uart_rxint:push PSWpush ACCpush DPLpush DPHclr RImov A,uart_rx_lengthcjne A,#UART_RX_SIZE,$+5hsjmp _uart_rxint_flowmov DPTR,#uart_rx_buffermov A,uart_rx_tailadd A,DPLmov DPL,Amov A,SBUFmovx @DPTR,Ainc uart_rx_tailanl uart_rx_tail,#UART_RX_SIZE_MASKinc uart_rx_length_uart_rxint_flow:jnb uart_enable_flow,_uart_rxint_exitjb UART_RTS,_uart_rxint_exitmov A,uart_rx_lengthanl A,#UART_RX_HIGH_MASKjz _uart_rxint_exitsetb UART_RTS_uart_rxint_exit:pop DPHpop DPLpop ACCpop PSWreti;--------------------;;;37;--------------------_uart_txint:push PSWpush ACCpush DPLpush DPHclr TIjnb uart_enable_term,$+6hjb UART_DSR,_uart_txint_clrrunflagjnb uart_enable_flow,$+6hjb UART_CTS,_uart_txint_clrrunflagmov A,uart_tx_lengthjnz $+4hsjmp _uart_txint_clrrunflagmov DPTR,#uart_tx_buffermov A,uart_tx_headadd A,DPLmov DPL,Amovx A,@DPTRmov SBUF,Ainc uart_tx_headanl uart_tx_head,#UART_TX_SIZE_MASKdec uart_tx_lengthsjmp $+4h_uart_txint_clrrunflag:clr uart_tx_running_flag
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -