📄 pic10f202.asm
字号:
;**************************************************************************************
;* Copyright 2005 Micron Technology, Inc. All rights reserved.
;*
;*
;* No permission to use, copy, modify, or distribute this software and/or
;* its documentation for any purpose has been granted by Micron Technology, Inc.
;* If any such permission has been granted ( by separate agreement ), it
;* is required that the above copyright notice appear in all copies and
;* that both that copyright notice and this permission notice appear in
;* supporting documentation, and that the name of Micron Technology, Inc. or any
;* of its trademarks may not be used in advertising or publicity pertaining
;* to distribution of the software without specific, written prior permission.
;*
;*
;* This software and any associated documentation are provided "AS IS" and
;* without warranty of any kind. MICRON TECHNOLOGY, INC. EXPRESSLY DISCLAIMS
;* ALL WARRANTIES EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, NONINFRINGEMENT
;* OF THIRD PARTY RIGHTS, AND ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS
;* FOR A PARTICULAR PURPOSE. MICRON DOES NOT WARRANT THAT THE FUNCTIONS CONTAINED
;* IN THIS SOFTWARE WILL MEET YOUR REQUIREMENTS, OR THAT THE OPERATION OF THIS SOFTWARE
;* WILL BE UNINTERRUPTED OR ERROR-FREE. FURTHERMORE, MICRON DOES NOT WARRANT OR
;* MAKE ANY REPRESENTATIONS REGARDING THE USE OR THE RESULTS OF THE USE OF ANY
;* ACCOMPANYING DOCUMENTATION IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY,
;* OR OTHERWISE.
;**************************************************************************************/
list p=10F202 ; list directive to define processor
#include <p10F202.inc> ; processor specific variable definitions
__CONFIG _MCLRE_ON & _CP_OFF & _WDT_OFF & _IntRC_OSC
; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
;******************************************************************************
;Defines
;******************************************************************************
#define SCLK GPIO,0
#define SDAT GPIO,1
#define RSTSOC GPIO,2
#define SERADDR 0xBA
;***** VARIABLE DEFINITIONS
SERdata equ 0x08 ; data to be sent via SER
count8 equ 0x09 ; counter to keep track of current SER bit
REGADDR equ 0x0a ; register address
HIGHBYTE equ 0x0b ; high byte of data to write via SER
LOWBYTE equ 0x0c ; low byte of data to write via SER
sdatstat equ 0x0d ; state of SDAT, 1 or 0
serack equ 0x0e ; state of SER acknowledge
tableoffset equ 0x0f ; for look-up table
endtable equ 0x10 ; signal end of lookup table
waitvar equ 0x11 ; for wait loop
waitvar2 equ 0x12 ; for wait loop
delay_num equ 0x13 ; 9-29 adding
;**********************************************************************
org 0x1FF ; processor reset vector
; Internal RC calibration value is placed at location 0x1FF by Microchip
; as a movlw k, where the k is a literal value.
org 0x000
;IF FLASH MEMORY IS ACCIDENTALLY ERASED UNCOMMENT THE LINE BELOW
movlw 0x00
movwf OSCCAL ; update register with factory cal value
goto start ; most subroutines are in the second half of memory
; to allow most of the first half to be used for
; the register programming table
;-----------------------------------------------------
;lookup table for SER register writes
PROGTABLE
addwf PCL, 1 ; add offset to PC
retlw 0xf0 ;page 0x01
retlw 0x00
retlw 0x01
retlw 0x13 ;
retlw 0x07
retlw 0x80
;retlw 0x15 ;
;retlw 0x00
;retlw 0x02 ;flip
retlw 0x25 ; color saturation 150%
retlw 0x00
retlw 0x2d
retlw 0xf0 ;page 0x00
retlw 0x00
retlw 0x00
retlw 0x20 ;
retlw 0x03
retlw 0x01 ;mirror
retlw 0x70 ;
retlw 0x9c
retlw 0x57
retlw 0x71 ;
retlw 0x9c
retlw 0x57
retlw 0x72 ;
retlw 0x61
retlw 0x59
retlw 0x73 ;
retlw 0x99
retlw 0x59
retlw 0x74 ;
retlw 0x7f
retlw 0x77
retlw 0x75 ;
retlw 0x7e
retlw 0x78
retlw 0x76 ;
retlw 0x98
retlw 0x79
retlw 0x77 ;
retlw 0x75
retlw 0x5d
retlw 0x78 ;
retlw 0x9b
retlw 0x53
retlw 0x79 ;
retlw 0x99
retlw 0x55
retlw 0x7a ;
retlw 0x9a
retlw 0x57
retlw 0x7b ;
retlw 0x9b
retlw 0x56
retlw 0x7c ;
retlw 0x9d
retlw 0x55
retlw 0x7d ;
retlw 0x75
retlw 0x5c
retlw 0x7e ;
retlw 0x00
retlw 0x9d
retlw 0x7f ;
retlw 0x9c
retlw 0x52
retlw 0xf0 ;page 0x02
retlw 0x00
retlw 0x02
retlw 0x3b ;
retlw 0x04
retlw 0xec
retlw 0x2e ;exposure time
retlw 0x09
retlw 0x6d
retlw 0xf0 ;page 0x00
retlw 0x00
retlw 0x00
retlw 0x12 ;
retlw 0x04
retlw 0xec
retlw 0x35 ;
retlw 0x20
retlw 0x24
retlw 0x38 ;
retlw 0x20
retlw 0x02
retlw 0xf0 ;page 0x01
retlw 0x00
retlw 0x01
retlw 0x05 ;
retlw 0x00
retlw 0x04
retlw 0x11 ;
retlw 0x00
retlw 0x03
retlw 0xdc ;
retlw 0x17
retlw 0x08
retlw 0xdd ;
retlw 0x4b
retlw 0x2e
retlw 0xde ;
retlw 0x94
retlw 0x75
retlw 0xDf ;
retlw 0xc0
retlw 0xac
retlw 0xe0 ;
retlw 0xe0
retlw 0xd1
retlw 0xe1 ;
retlw 0x00
retlw 0x00
retlw 0xf0 ;page 0x00
retlw 0x00
retlw 0x00
retlw 0x30 ;
retlw 0x08
retlw 0x2a
retlw 0xf0 ;page 0x01
retlw 0x00
retlw 0x01
retlw 0x3b ;
retlw 0x04
retlw 0x1e
retlw 0xf0 ;page 0x02
retlw 0x00
retlw 0x02
retlw 0x36 ;
retlw 0xa0
retlw 0x10
retlw 0x2e ;
retlw 0x00
retlw 0x00
retlw 0x24 ;
retlw 0x54
retlw 0x2b
retlw 0x29 ;
retlw 0x9c
retlw 0x64
retlw 0x5e ;
retlw 0x77
retlw 0x3e
retlw 0x5f ;
retlw 0xff
retlw 0x84
retlw 0x28 ;
retlw 0xef
retlw 0x09
retlw 0x1f ;
retlw 0x00
retlw 0xa6
retlw 0x2a ;
retlw 0x00
retlw 0x00
retlw 0xf0 ;page 0x01
retlw 0x00
retlw 0x01
retlw 0x06 ;
retlw 0xe4
retlw 0x0e
;call wait70ms ; wait 70 ms
;call wait70ms ; wait 70 ms
;call wait70ms ; wait 70 ms
;call wait70ms ; wait 70 ms
retlw 0x06 ;
retlw 0x64
retlw 0x0e
retlw 0xf0 ;page 0x02
retlw 0x00
retlw 0x02
retlw 0x2e ;
retlw 0x08
retlw 0x3c
retlw 0x02 ;
retlw 0x00
retlw 0xae
retlw 0x03 ;
retlw 0x39
retlw 0x23
retlw 0x04 ;
retlw 0x07
retlw 0x24
retlw 0x09 ;
retlw 0x00
retlw 0x8d
retlw 0x0a ;
retlw 0x00
retlw 0x1a
retlw 0x0b ;
retlw 0x00
retlw 0x00
retlw 0x0c ;
retlw 0x00
retlw 0x66
retlw 0x0d ;
retlw 0x00
retlw 0xd6
retlw 0x0e ;
retlw 0x00
retlw 0x46
retlw 0x0f ;
retlw 0x00
retlw 0x14
retlw 0x10 ;
retlw 0x00
retlw 0xa4
retlw 0x11 ;
retlw 0x00
retlw 0xdc
retlw 0x0f ;
retlw 0x00
retlw 0x03
retlw 0x10 ;
retlw 0x00
retlw 0x1b
retlw 0x11 ;
retlw 0x00
retlw 0x8f
;-------------
retlw 0xf0
retlw 0x00
incf endtable, 1 ; this line goes before the last retlw
retlw 0x01
;-------------
;-----------------------------------------------------
SENDSERPACKET
goto SENDSERPACKET_
SERSTART
goto SERSTART_
SERSENDBYTE
goto SERSENDBYTE_
SERGETACK
goto SERGETACK_
SERSTOP
goto SERSTOP_
wait70ms
goto wait70ms_
;-----------------------------------------------------
org 0x100
start
nop ; example code
movlw 0xDF
option; enable using GPIO2
;--------------------------
clrf endtable
clrf tableoffset
;---
movlw 0xff
movwf count8
movlw 0x0b
tris GPIO; set RST to output
bcf RSTSOC; assert low
resetSOC
decfsz count8, 1
goto resetSOC
movlw 0x0f
tris GPIO; deassert RST
foreverloop
;goto foreverloop
; main loop
clrf delay_num ; 9-29 adding
regwriteloop
movf tableoffset, 0 ; move table offset to w register
call PROGTABLE
movwf REGADDR
;---
incf tableoffset, 1 ; increment table offset
movf tableoffset, 0 ; move table offset to w register
call PROGTABLE
movwf HIGHBYTE
;---
incf tableoffset, 1 ; increment table offset
movf tableoffset, 0 ; move table offset to w register
call PROGTABLE
movwf LOWBYTE
;---
call SENDSERPACKET ; write SER
;---
btfss serack, 0 ; check for SER acknowledge
goto continueloop
decf tableoffset, 1 ; decrement offset to repeat failed SER write
decf tableoffset, 1
goto regwriteloop
;---
continueloop
; 9-29 adding
incf delay_num,F
movf delay_num,W
xorlw .54
btfsc STATUS,Z
goto DELAY_500ms
goto continueloop1
DELAY_500ms
call wait70ms ; wait 70 ms
call wait70ms ; wait 70 ms
call wait70ms ; wait 70 ms
continueloop1
incf tableoffset, 1 ; increment table offset
btfss endtable, 0 ; end program if endtable is 1
goto regwriteloop
call wait70ms ; wait 70 ms
call wait70ms ; wait 70 ms
call wait70ms ; wait 70 ms
call wait70ms ; wait 70 ms
;--------------------------
movlw 0x06 ;OPERATINGMODECONTROL-AWB
movwf REGADDR
movlw 0x60
movwf HIGHBYTE
movlw 0x0E
movwf LOWBYTE
call SENDSERPACKET
;--------------------------
;--------------------------
movlw 0xf0
movwf REGADDR
movlw 0x00
movwf HIGHBYTE
movlw 0x02
movwf LOWBYTE
call SENDSERPACKET
;--------------------------
;--------------------------
movlw 0x2E ;AE_PRECISION_TARGET-normal
movwf REGADDR
movlw 0x08
movwf HIGHBYTE
movlw 0x31
movwf LOWBYTE
call SENDSERPACKET
;--------------------------
endprog
sleep
;-----------------------------------------------------
SENDSERPACKET_
movlw SERADDR
movwf SERdata
SENDADDR
call SERSTART
call SERSENDBYTE
call SERGETACK
btfsc serack, 0
goto SERSTOP
;-------------------
movf REGADDR, 0
movwf SERdata
SENDREGADDR
call SERSENDBYTE
call SERGETACK
btfsc serack, 0
goto SERSTOP
;-------------------
movf HIGHBYTE, 0
movwf SERdata
SENDDATAH
call SERSENDBYTE
call SERGETACK
btfsc serack, 0
goto SERSTOP
;-------------------
movf LOWBYTE, 0
movwf SERdata
SENDDATAL
call SERSENDBYTE
call SERGETACK
btfsc serack, 0
goto SERSTOP
;-------------------
call SERSTOP
retlw 0
;-----------------------------------------------------
SERSTART_
bcf SCLK
movlw 0x0E
tris GPIO; set SCLK to 0
bcf SDAT
movlw 0x0F
tris GPIO; set SCLK to 1
movlw 0x00
movwf sdatstat
movlw 0x0D
tris GPIO; set SDAT to 0
retlw 0
;-----------------------------------------------------
SERSTOP_
movf sdatstat,1
movlw 0x0E
tris GPIO; clear SCLK
movlw 0x0C
tris GPIO; clear SDAT
movlw 0x0D
tris GPIO; set SCLK
movlw 0x0F
tris GPIO; set SDAT
retlw 0
;-----------------------------------------------------
SERSENDBYTE_
movlw 0x80
movwf count8
BYTELOOP
movf sdatstat,1; test sdatstat
btfsc STATUS, 2; check Z flag
goto CLK0
movlw 0x0E
tris GPIO
CLK0
movlw 0x0C
tris GPIO; SCLK and SDAT output
movf SERdata, 0; move SERdata to W
andwf count8, 0; AND SERdata with count8 and store in W
btfsc STATUS, 2; check for Z flag
goto NEXTPRE
movlw 0x0E; SDAT input
tris GPIO
movlw 0x01
movwf sdatstat; status shows sdat is 1
goto NEXT
NEXTPRE
movlw 0x00
movwf sdatstat
NEXT
;if sdatstat is 0x01, set tris to 0x0F
;else set tris to 0x0D
movf sdatstat,1; test sdatstat
btfss STATUS, 2
goto NEXT2
movlw 0x0D
tris GPIO
goto NEXT3
NEXT2
movlw 0x0F
tris GPIO
NEXT3
bcf STATUS, 0; clear CARRY flag
rrf count8, 1
btfss STATUS, 0; skip if CARRY is set
goto BYTELOOP
retlw 0
;-----------------------------------------------------
SERGETACK_
movf sdatstat,1; test sdatstat
btfsc STATUS, 2; check Z flag
goto NEXT4
movlw 0x0E
tris GPIO; clear SCLK and leave SDAT
NEXT5
movlw 0x01
movwf sdatstat
movlw 0x0F
tris GPIO; set SCLK
;--
nop
clrf serack
btfsc SDAT
incf serack, 1
;--
retlw 0
NEXT4
movlw 0x0C
tris GPIO; clear SCLK
movlw 0x0E
tris GPIO; set SDAT
goto NEXT5
;-----------------------------------------------------
wait70ms_
movlw 0xff ; move 0xff to work register
movwf waitvar ; move contents of work register to waitvar variable
movwf waitvar2 ; move contents of work register to waitvar variable
wait70msloop
decfsz waitvar2, 1 ;decrement waitvar2 and skip the next instruction if the result is 0
goto wait70msloop ;
movlw 0xff ;
movwf waitvar2 ;move 0xff into waitvar2
decfsz waitvar, 1 ;decrement waitvar and skip the next instruction if the result is 0
goto wait70msloop ;
retlw 0 ;return
;-----------------------------------------------------
END ; directive 'end of program'
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -