⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.asm

📁 A very good POCSAG Paging Protocol Decoder.
💻 ASM
📖 第 1 页 / 共 2 页
字号:
        mov [bit_ptr], A                                           
        mov [hi_cnt], A
        mov [lo_cnt], A
        mov [byte_cnt], A
        mov [data], A
        mov [start], 1              ;set start flag    
        mov A, [sampling_rate]      ;rate for sampling
        call Timer8_1_WritePeriod   ;write timer period
        M8C_EnableGInt              ;enable Global INT
    
   
lp_sample:  nop                                     ;wait until counter reaches
			cmp [sample_cnt], SAMPLE_NUM            ;number SAMPLE_NUM
			jc lp_sample                            
			M8C_DisableGInt                         ;disable Global INT   
			mov A, [hi_cnt]
			cmp A, [lo_cnt]							;if hi_cnt < lo_cnt
			jc .brn_temp							;do nothing
			or [data], 1                            ;else, LSB bit of data set to 1  
.brn_temp:      		
            mov A, 0                                
            mov [hi_cnt], A                         ;reset hi_cnt
            mov [lo_cnt], A                         ;reset lo_cnt
            mov [sample_cnt], A                     ;reset sampling counter
            M8C_EnableGInt                          ;enable Global INT
            mov A, [bit_ptr]
            cmp A, MSB_NUM                          
            jz lp_next_byte                         ;if bit_ptr != MSB_NUM
            inc A                                   ;inc. bit_ptr
            mov [bit_ptr], A
            asl [data]                              ;shift data to the left
            jmp lp_sample                           ;start sampling again
            
lp_next_byte:
            ;if bit_ptr == MSB_NUM
            mov A, [byte_cnt]
            jnz lp_not_first_byte                   ;if byte_cnt == 0
            mov A, [batch_cnt]                      
            jnz lp_not_first_batch                  ;and if batch_cnt == 0
            mov A, [data]
            mov X, A
            cmp A, 0x54                             ;if data != 0x54
            jz lp_first_byte                                       
            cpl A                                   ;invert data
            cmp A, 0x54                             ;check again, if data != 0x54
            jz lp_first_byte                        
            asl [data]                              ;shift data to the left
            jmp lp_sample                           ;start sampling again
            
lp_first_byte:
            ;if data or inverted data == 0x54
            mov A, X
            cmp A, 0xAB                             ;if data is inverted
            jnz .temp
            mov [inverse], 1                        ;set inverse flag
.temp:      
			asl [data]                              ;shift data to the left
			mov [bit_ptr], 1                        ;set bit_ptr to 1 (first bit after preambule)
			inc [byte_cnt]                          ;inc. byte_cnt
			jmp lp_sample                           ;start sampling again
			
lp_not_first_batch:
            ;if byte_cnt == 0 and batch_cnt != 0
            mov A, [data]
            cmp [inverse], 1                        ;if inverse == 1
            jnz .temp
            cpl A                                   ;inverse data
.temp:      
            cmp A, 0x7C                             ;if data != begining of the next batch
            jnz lp_end                              ;end receving
            inc [byte_cnt]			                ;else inc. byte_cnt
			
lp_not_first_byte:
            ;if byte_cnt != 0
            mov [bit_ptr], 0                        ;reset bit_ptr
            mov A, [data]			                
            cmp [inverse], 1                        ;if inverse == 1
            jnz .temp
            cpl A                                   ;inverse data
.temp:
            call  TX8_1_SendData					;send data into UART
            mov A, [byte_cnt]
            cmp A, BYTE_NUM                         
            jz  lp_next_batch                       ;if byte_cnt != BYTE_NUM
            inc A                                   ;inc. byte_cnt
            jmp lp_save_cnt
lp_next_batch:
            inc [batch_cnt]                         ;else inc. batch_cnt
            mov A, 0                                ;reset byte_cnt
lp_save_cnt:                                        
            mov [byte_cnt], A
            mov [data], 0                           ;reset data
            jmp lp_sample                           ;start sampling again
            
lp_end:
            ;end receiving 
            mov REG[PRT2DR], 00h        			;turn rate LEDs OFF
            mov [inverse], 0                        ;reset inverse
            mov [batch_cnt], 0                      ;reset batch_cnt
			mov [start], 0                          ;reset start flag
            mov A, FFh                              ;timer period 2ms                 
            call Timer8_1_WritePeriod               ;write timer period
            M8C_DisableIntMask  INT_MSK0, INT_MSK0_AColumn0 ;enable analog0 int
            M8C_EnableIntMask  INT_MSK0, INT_MSK0_GPIO ;enable input INT
            jmp l_start                             ;start over
            
            ret            	
   
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::   
; Name      : TIMER8_1_ISR
; Desc.     : Interrupt Service Routine for the timer
; Input     : None
; Output    : None
; Operation : Serves Digital0 interrupt used by Timer. It will test comparator 
;             output and increment corresponding counter. It will also increment
;             sampling counter 
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::         
TIMER8_1_ISR:                       
            tst REG[CMP_CR], 0x10                   ;mask comp 0
            jz brn_isr_bit0                         ;if comp != 0
            inc [hi_cnt]                            ;inc. hi_cnt
            jmp brn_isr_end
brn_isr_bit0:
            inc [lo_cnt]                            ;else inc. lo_cnt
brn_isr_end:
            inc [sample_cnt]                        ;inc. sample_cnt
            
            reti        
 
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::   
; Name      : GPIO_ISR
; Desc.     : Interrupt Service Routine for GPIO
; Input     : None
; Output    : None
; Operation : Serves GPIO interrupt enabled on P1[7] as "change of state" type.
;             If start flag is 0, it will read timer count, restart timer with 
;             2msec. period and set ready flag. If start flag is set, it will 
;             restart counter, enable comparator interrupt and disable GPIO.
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::           
GPIO_ISR:                          
            push A
            mov A, REG[PRT1DR]                      ;read input port
            mov A, [start]                          ;if start == 0
            jnz .brn_isr_start
            mov [ready], 1                          ;set ready flag
            call bTimer8_1_ReadTimer                ;read timer count
            mov [rate], A                           ;save timer count as rate
            call Timer8_1_Stop                      ;stop timer 
            mov A, FFh
            call Timer8_1_WritePeriod               ;write timer period
            mov A, 00h
            call Timer8_1_WriteCompareValue         ;write timer compare value
            call Timer8_1_Start                     ;start timer  
            jmp .brn_isr_end
.brn_isr_start:
            ;statr == 1
            call Timer8_1_Stop
            call Timer8_1_Start
            M8C_DisableIntMask  INT_MSK0, INT_MSK0_GPIO ;disable input INT
            M8C_EnableIntMask  INT_MSK0, INT_MSK0_AColumn0 ;enable analog0 int
.brn_isr_end:         
            pop A
            reti             
 
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::   
; Name      : GPIO_ISR
; Desc.     : Interrupt Service Routine for Comparator
; Input     : None
; Output    : None
; Operation : Serves Analog0 interrupt used by comparator. On the rising edge it
;           ; will synchronize sampling count to the begining of new bit
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::           
COMP_ISR:                         
			cmp [sample_cnt], 5						
			jc .brn_isr_left                        ;if sample_cnt. > SAMPLE_NUM/2
			mov [sample_cnt], SAMPLE_NUM            ;set sample_cnt = SAMPLE_NUM
			jmp .brn_isr_right
.brn_isr_left:
            mov [sample_cnt], 0                     ;esle sample_cnt = 0
            mov [hi_cnt], 0                         ;reset hi_cnt
            mov [lo_cnt], 0                         ;reset lo_cnt
.brn_isr_right:
            reti                                       		                        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -