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

📄 main.asm

📁 A very good POCSAG Paging Protocol Decoder.
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;-----------------------------------------------------------------------------
; File		: main.asm
; Decs.     : This file contains functions for POCSAG_Decoder project.
; Operation : Search for POCSAG preambule, identify data bit rate, perform 
;             synchronization to receiving packet, copy it into UART 
;-----------------------------------------------------------------------------
include "m8c.inc"					;include m8c specific declarations 
include "cmpprg_1.inc"              ;include CMPPRG_1 module specific declarations
include "timer8_1.inc"              ;include Timer8_1 module specific declarations
include "tx8_1.inc"					;include TX8_1 module specific declarations
include "pga_1.inc"                 ;include PGA_1 module specific declarations

export _main
export GPIO_ISR
export TIMER8_1_ISR
export COMP_ISR

RATE_2400_HI:   	  EQU 218            ;Upper margin for 2400 bps data rate
RATE_2400_LO:    	  EQU 188            ;Lower margin for 2400 bps data rate
RATE_1200_HI:   	  EQU 181            ;Upper margin for 1200 bps data rate
RATE_1200_LO:   	  EQU 121            ;Lower margin for 1200 bps data rate
RATE_512_HI:    	  EQU 71             ;Upper margin for 512 bps data rate
RATE_512_LO:    	  EQU 1              ;Lower margin for 512 bps data rate
RATE_CHECK:     	  EQU 255            ;Number of time to check data rate
SAMPLING_RATE_2400:   EQU 5  	         ;6-1, Timer period for 2400 bps sampling 
SAMPLING_RATE_1200:   EQU 11      	     ;12-1, Timer period for 1200 bps sampling 
SAMPLING_RATE_512:    EQU 26        	 ;27-1, Timer period for 512 bps sampling
SAMPLE_NUM:    		  EQU 9              ;Number of time to sample comparator output in one period
MSB_NUM:      	      EQU 7              ;Number of bit shifts in one byte 
BYTE_NUM:       	  EQU 68             ;Number of bytes in one batch      

area 	bss(RAM)					;inform assembler that variables follow

ready:           blk 1              ;flag that GPIO interrupt is occured
start:           blk 1              ;flag to disable GPIO and enable COMP interrupts
rate:            blk 1              ;period of received data
bit_ptr:         blk 1              ;pointer to bit position in the byte
hi_cnt:          blk 1              ;counter of positive values
lo_cnt:          blk 1              ;counter of negative values
data:            blk 1              ;byte of combined received bits
byte_cnt:        blk 1              ;counter of received bytes 
sample_cnt:      blk 1              ;counter of comparator sampling times
sampling_rate:   blk 1              ;timer period for comparator sampling
saved_bit:       blk 1              ;previos result of rate search
inverse:         blk 1              ;flag that received data is inverted
batch_cnt:       blk 1              ;counter of batches have been received

area	text(ROM,REL)				;inform assembler that program code follws

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::   
; Name      : _main
; Desc.     : Main function for POCSAG Decoder
; Input     : None
; Output    : None
; Operation : Called from boot.asm after initialization. It will find POCSAG data 
;             packet, synchronize to it, and copy into UART  
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
_main:
     ;UART Init: 9600, 8-N-1
     mov	  A,0
	 call  TX8_1_Start
	 call  Counter8_2_Start			
     
     ;Comparator Init:
     mov   A, CMPPRG_1_HIGHPOWER      
     call CMPPRG_1_SetPower          
     mov   A, CMPPRG_1_REF0_312      
     call CMPPRG_1_SetRef            
     
     ;PGA Init
     mov A, PGA_1_HIGHPOWER         
     call PGA_1_Start                 
     mov A, PGA_1_G2_00               
     call PGA_1_SetGain               
     
        
        mov reg[PRT0DR], 80h        ;POWER LED ON 
		
		;Power-ON LEDs test
		mov reg[PRT2DR], 07h        ;rate LEDs ON
    	mov reg[RES_WDT], 38h       ; reset the sleep timer
    	or	reg[INT_MSK0],40h		;enable sleep interrupt
		M8C_EnableGInt				;enable global interrupts 
    
lp_sleep:                           ;Sleep timer period is 1 sec.,
    	mov A, reg[INT_MSK0]        ;ones interrupt is ocurred, it will be disabled
    	jnz lp_sleep                ;so wait untill INT_MSK0 is zero!
    	M8C_DisableGInt             ;disable Global INT     
        mov REG[PRT2DR], 00h        ;rate LEDs OFF
        
        ;Varibles Init
        mov [inverse], 0                        ;reset inverse flag
        mov [batch_cnt], 0                      ;reset batch counter
        mov [sample_cnt], 0            		    ;reset sampling counter
        mov [bit_ptr], 0			            ;reset bit pointer
    	mov [ready], 0        			        ;reset ready flag
    	mov [start], 0                          ;reset start flag
    	
    	;Timer Init
        mov A, FFh                              ;timer period 2ms                   
        call Timer8_1_WritePeriod               ;write timer period
        nop
        call Timer8_1_Start                     ;start timer
        call Timer8_1_EnableInt                 ;enable timer INT 
        M8C_EnableIntMask  INT_MSK0, INT_MSK0_GPIO ;enable GPIO INT
    
l_start:                                 
        
        M8C_EnableGInt              ;enable Global INT
            
l_wait: nop                         ;wait untill ready flag is set
        mov A, [ready]              
        jz l_wait                   
        
        M8C_DisableGInt             ;disable Global INT
        mov [ready], 0              ;reset ready flag     
        mov A, [sample_cnt]         ;check for timer overflow
        jz l_search                 ;
        mov [sample_cnt], 0         ;reset sample_cnt
        mov [bit_ptr], 0            ;reset bit_ptr        
        jmp l_start                 ;start over    
        
l_search:
        ;if timer is not overflows, check data rate
		mov X, 0
        mov A, [rate]               ;load rate into Acc.        
        cmp A, RATE_2400_HI         
        jnc brn_search_end          ;finish search if rate > 2400 hi margin
        cmp A, RATE_2400_LO          
        jc  brn_search_1200         ;continue if rate < 2400 lo margin 
        mov X, 01h                  ;it is in 2400 range, set bit 0  
        mov [sampling_rate], SAMPLING_RATE_2400        ;set sampling rate    
        jmp brn_search_end          ;finish search
        
brn_search_1200:                    
        cmp A, RATE_1200_HI         
        jnc brn_search_end          ;finish search if rate > 1200 hi margin  
        cmp A, RATE_1200_LO              
        jc  brn_search_512          ;;continue if rate < 1200 lo margin
        mov X, 02h                  ;it is in 1200 range, set bit 1
        mov [sampling_rate], SAMPLING_RATE_1200        ;set sampling rate
        jmp brn_search_end          ;finish search
        
brn_search_512:                     
        cmp A, RATE_512_HI          
        jnc brn_search_end          ;finish search if rate > 512 hi margin
        cmp A, RATE_512_LO               
        jc  brn_search_end          ;finish search if rate < 512 lo margin 
        mov X, 04h                  ;it is in 512 range, set bit 3
        mov [sampling_rate], SAMPLING_RATE_512         ;set sampling rate
        
brn_search_end:           
        mov A, X                    
        jnz l_preamb                ;if rate does not match
        mov [bit_ptr], 0            ;reset bit_ptr
        jmp l_start                 ;start over

l_preamb:                           
        ;if rate does match
        mov A, [bit_ptr]            
        jnz brn_ptr_1               ;if it is the first bit
        inc [bit_ptr]               ;increment bit_ptr
        mov [saved_bit], X          ;save search result as saved_bit
        jmp l_start                 ;start for the next bit
        
brn_ptr_1:                          
        ;if it is not first bit
        mov A, X                    
        and A, [saved_bit]          ;if search result does not 
        jnz brn_ptr_2               ;match previos results
        mov [bit_ptr], 0            ;reset bit_ptr
        jmp l_start                 ;start over
        
brn_ptr_2:                          
        ;if search result matches previos one
		inc [bit_ptr]               ;increment bit_ptr
        cmp [bit_ptr], RATE_CHECK   ;if counter does not reach RATE_CHECK  
        jc  l_start                 ;start for the next bit
        
        ;if search result shows valid data rate and it consistent
        ;for RATE_CHECK times, assume that receiving data is POCSAG preambule.
        ;Init varibles, set start flag and set timer period to recived data rate
        mov REG[PRT2DR], A          ;turn 512, 1200, or 2400 rate LED             
        mov A, 0

⌨️ 快捷键说明

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