pIC查大表程序
list p=16c77 ;list directive to define processor
#include <p16c77.inc> ;processor specific variable definitions
__CONFIG _CP_OFF & _WDT_ON & _BODEN_ON & _PWRTE_ON & _XT_OSC
cbLOCk 0x20
w_temp ;variable used for context saving
status_temp ;variable used for context saving
index:2 ;index for larger table look-up
endc
;**********************************************************************
ORG 0x000 ; processor reset vector
clrf PCLATH ; ensure page bits are claared
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
; isr code CAN go here or be located as a call subroutine elsewhere
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
main
;测试程序,取表中第800位置的内容
movlw low(.800) ;get low byte of pointer
movwf index ;set to index buffer
movlw high(.800) ;get high byte of pointer
movwf index+1 ;set to index+1 buffer
pagesel LTABLE ;make sure page is set correctly
call LTABLE ;call table look-up
;index will be scrambLED after call
pagesel $ ;make sure page is current
goto $ ;code stop here
;This table can be any size and can be located at any position
;regardless of page issue
org 1000H
LTABLE
movlw low(_table_start) ;get the low byte of actual start address
addwf index,f ;calculate for low byte offset
skpnc ;is CARRY?
incf index+1,f ;yes, consider CARRY bit
movlw high(_table_start) ;get the high byte of actual start address
addwf index+1,f ;calculate for high byte offset
;now the data pointer is set in index
movf index+1,w ;let PC jump to that location
movwf PCLATH
movf index,w
movwf PCL ;PC change now!!!
_table_start
DT 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f
DT 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f
DT 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f
DT 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f
DT 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f
[1] [2] [3] 下一页
本文关键字:程序 PIC单片机,单片机-工控设备 - PIC单片机