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

📄 camerasw.asm

📁 这是笔者早年开发的一款用单片机读摄象头图象数据的程序
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;===================================
;-----------------------------------
;file name  Carme controler
#include    "reg52.inc"
;-----------------------------------
;===================================
;-----------------------------------
;Ram Map :

;bank0:globle variable:
;00h~07h
;r0: 
;r1:
;r2:
;-----
;r3:special for getting frame image 
;r4:special for getting frame image
;r5:special for getting frame image 
;r6:special for getting frame image
;r7:special for getting frame image
;-----------------------------------

;bank1:globle variable
;08h~0fh
;r0:re_buf_addr_ptr:range=20h~2Fh ;(16 bytes)
	re_buf_addr_ptr data 08h	
	UartReBufHeadAddrPtr equ 20h
;r1:checksum for counting datum received
	re_checksum_counting data 09h
;r2:number of receiving datum 
	re_byte_number  data 0Ah
;r3:uart_re_status
	uart_re_status  data 0Bh
	RecDataFinished equ 80h
	RecDataReadyAll equ 00h
;r4:tr_buf_addr_ptr:range=10h~1Fh ;(16 bytes)   
	tr_buf_addr_ptr data 0Ch
	UartTrBufHeadAddrPtr equ 10h
;r5:checksum for conting datum transmited
	tr_checksum_counting data 0Dh
;r6:number of transmit datum
	tr_byte_number data 0Eh
;r7:uart_tr_status
	uart_tr_status data 0Fh
;---------------------------------data
;10h~1Fh:transmiting datum buffer
;20h~2Fh:receiving datum buffer
;---------------------------------data
;30h~3fh:window coordinate counting buffer 
;3eh,3fh:special for transform Hex. into Dec.
	WindowCountBufHeadAddr equ 30h
;40h~4fh:window coordinate check buffer
	WindowCheckBufHeadAddr equ 40h
;50h~7fh:stack
;---------------------------------idata
;80h~ffh:null
;-----------------------------------
/*
	uart_buf_pointer data 08h ;r0 of bank1
	uart_checksum    data 09h ;r1 of bank1
	uart_amount      data 0ah ;r2 of bank1
	uart_type        data 0bh ;r3 of bank1
		uart_null        equ    00h
		uart_receive     equ    01h
		uart_sending     equ    02h
	;... 
	uart_buf_head       equ  20h
	uart_command_type data 21h
	uart_data_long    data 21h;
*/
	;-----------------------------------
;  command type between pc and C3188-controller 	
	CmmdType_SCCB_Option         equ  01h
 	CmmdType_ObtainImageFrame    equ  02h
	CmmdType_SendImageLineDatum  equ  03h
	
	WriteSCCB_SlaveDeviceID   equ 42h
	ReadSCCB_SlaveDeviceID    equ 43h
	;-----------------------------------
;	Horizontal window start value limited : 2fh~7eh == 0001~0320
	WindowRowStartBaseValue  equ 2fh
;	Horizontal window end value limited : 7fh~cfh  == 0321~0640
	WindowRowEndBaseValue    equ 7fh
	;-----------------------------------
;	vertical window start value limited : 06h~7dh == 0001~0240
	WindowColumnStartValue  equ 06h
;	Vertical window end  value limited : 7eh~f5h == 0241~0480
	WindowColumnEndValue equ 7eh
	;-----------------------------------
	;-----------------------------------
	;-----------------------------------
Y_EN      bit  p1.0
	LogicRuler_Y_EN      equ 01h
I2C_SDA   bit  p1.1
	LogicRuler_I2C_SDA   equ 02h					
I2C_SCL   bit  p1.2
	LogicRuler_I2C_SCL   equ 04h
;PageAddr_OE   bit  p1.3
;	LogicRuler_Page_Addr equ 08h
CTR_485   bit  p1.4
	LogicRuler_CTR_485   equ 10h
ISP_MOSI  bit  p1.5
	LogicRuler_ISP_MOSI  equ 20h
ISP_MISO  bit  p1.6
	LogicRuler_ISP_MISO  equ 40h
ISP_SCK   bit  p1.7
	LogicRuler_ISP_SCK   equ 80h
;-----------------------------------
RXD_485   bit  p3.0
TXD_485   bit  p3.1
HREF      bit  p3.2
PCLK      bit  p3.3
VSYNC     bit  p3.4
PageAddr_LE   bit  p3.5
WR_RAM    bit  p3.6
RD_RAM    bit  p3.7
;-----------------------------------
;===================================
;-----------------------------------
Int0_ADDR        EQU  0003h
T0_ADDR          EQU  000BH
Int1_ADDR        EQU  0013h
T1_ADDR          EQU  001BH
Uart_ADDR        EQU  0023H
;-----------------------------------
;===================================
;	USING	0 	       
		cseg
	org  0000h
	nop
	ajmp  main_start
	
	org  Int0_ADDR
	ajmp Int0_serve_HREF
	
	org  T0_ADDR
	ajmp T0_Serve_VSYNC
	
	org  Int1_ADDR
	ajmp Int1_serve_PCLK
	
	;org  T1_ADDR
	;ajmp T1_serve
	
	org   Uart_ADDR
	ajmp  Uart_Serve
;-----------------------------------
	org   0060H
	;---------------
main_start:
	;---------------
	clr ea
	mov P0,#0ffh     ;setup p0 as input pin
	mov a,P0
	setb	Y_EN       ;Y_enable	 low active
	;setb	PageAddr_OE  ;bit  p1.3 low active
	setb	PageAddr_LE  ;bit  p3.5 low active
	;---------------close interrupt
	clr ea
	;---------------p1 
	;MOV P1,#06H  ;     p1.0,p1.1,p1.2,p1.3,p1.4,p1.5
	;---------------sccb
 	setb I2C_SDA
	setb I2C_SCL
	;---------------T0/T1
	mov IP,  #10H;     x|x|x|PS|T1|X1|T0|X0
	mov scon,#50h;     SM0|SM1|SM2|REN|TB8|RB8|TI|RI
	mov IE,  #10h;     ea|x|eT2|es|eT1|eX1|eT0|eX0
	mov TMOD,#66h;     T1-> GATE|C/not(T)|M1|M0|GATE|C/not(T)|M1|M0<-T0
	mov tcon,#0f5h;     TF1|TR1|TF0|TR0|IE1|IT1IE0|IT0
	;----------------------
	mov pcon,#00h;      9600 baud need pcon=80h,smod=0	
	mov th1,#0ffh;      x=256-fosc(smod+1)/(384*band)
	mov tl1,#0ffh;      9600 baud mod=0 #0f7h when 33Mhz
	mov th0,#0ffh;
	mov tl0,#0ffh;
	;----------------------	
	;----------------------
	mov IE,#10h;        ea|x|eT2|es|eT1|eX1|eT0|eX0  !!! only enable es int
	mov sp,#50h;
	setb ea	  ;;       !!!	
	;----------------------
	call uart_re_init
	call uart_tr_init
;-------------------------------------
;sccb_settingup   equ  01h
;obtain_image     equ  02h
;send_image_datum equ 03h
;-------------------------------------
main_loop: 
	;----------------------
	;----------------------
	call to_processing_sccb
	;----------------------
	call to_get_frame_image
	;----------------------
	call send_image_line_datum
	;----------------------
	ajmp main_loop
;-------------------------------------
;-------------------------------------
;-------------------------------------
;-------------------------------------
;-------------------------------------
;=====================================
;-------------------------------------
to_processing_sccb:
	;----------------
	mov a,uart_re_status;;  data 0Bh
	cjne a,#RecDataFinished,end_processing_sccb
	;----------------
	mov a,#UartReBufHeadAddrPtr;; equ  20h
	mov r0,a     
	mov a,@r0
	cjne a,#CmmdType_SCCB_Option,end_processing_sccb
	;----------------
	inc r0
	mov a,@r0	;the amount of the datum
	clr c
	rrc a
	mov r2,a	   ;the amount of sccb command that will be sent to ov7620
	inc r0      ;address pointer of data_1
	;----------------
	call Send_SCCB_to_OV7620
	mov a,#RecDataReadyAll;; equ 00h
	mov uart_re_status,a  ;;  data 0Bh
	;----------------
	call reply_PC
	;===============================
end_processing_sccb:
WRS60:
	ret
;-------------------------------------
;=====================================
;-------------------------------------
	;input r0 <--first data address pointer 
	;      r2 <--amount of sccb command that will be sent to ov7620
Send_SCCB_to_OV7620:	
	;---------
	CALL START_BIT_I2C;起始位
	;---------
	dec r0
enable_SCCB_to_OV7620:	
	;---------	
	inc r0
	mov a,@r0
	jnb acc.7,write_sccb_toOV7620  ;acc.7=0 is write / acc.7=1 is read 
	;---------
read_sccb_fromOV7620:
	;WriteSCCB_SlaveDeviceID   equ 42h
	;ReadSCCB_SlaveDeviceID    equ 43h
	mov a,#ReadSCCB_SlaveDeviceID
	CALL TX_BYTE_I2C
   CALL RECEIVE_ACK		
	;CJNE A,#00H,end_processing_sccb
	;----
	mov a,@r0
	anl a,#7Fh
	CALL TX_BYTE_I2C
   CALL RECEIVE_ACK	
	;CJNE A,#00H,end_processing_sccb
	;----
	CALL RX_BYTE_I2C
	inc r0
	mov @r0,a
	CALL RECEIVE_ACK	
	;CJNE A,#00H,end_processing_sccb
	;---------
	jmp next_sccb_data
	;----------------
write_sccb_toOv7620:
	;WriteSCCB_SlaveDeviceID   equ 42h
	;ReadSCCB_SlaveDeviceID    equ 43h
	mov a,#WriteSCCB_SlaveDeviceID
	CALL TX_BYTE_I2C
   CALL RECEIVE_ACK		
	;CJNE A,#00H,end_processing_sccb
	;----
	mov a,@r0
	anl a,#7Fh
	CALL TX_BYTE_I2C
   CALL RECEIVE_ACK	
	;CJNE A,#00H,end_processing_sccb
	;----
	inc r0
	mov a,@r0
	CALL TX_BYTE_I2C
   CALL RECEIVE_ACK	
	;CJNE A,#00H,end_processing_sccb
	;---------
next_sccb_data:
	djnz r2,enable_SCCB_to_OV7620
	;----------------
	CALL STOP_BIT_I2C
	;----------------
	Ret
;-------------------------------------
;=====================================
;-------------------------------------
to_get_frame_image:
	;----------------------------------
	mov a,uart_re_status;;  data 0Bh
	cjne a,#RecDataFinished,end_get_frame_image
	;-------
	mov r0,#UartReBufHeadAddrPtr;; equ 20h
	mov a,@r0	
	cjne a,#CmmdType_ObtainImageFrame,end_get_frame_image
	;----------------------------------
	inc r0
	mov a,@r0	;the amount of the data
	cjne a,#09h,to_get_frame_image_01
	jmp to_get_frame_image_02
	;-------
to_get_frame_image_01:
	cjne a,#0ah,err_end_get_frame_image
	;----------------------------------
to_get_frame_image_02:
	;-------
	call WindowRangeDataToCheckBuf
	call WindowRangeCheckValueCounting
	;-------
	call GetWindowRangDatum
	call WindowCoordinateX1Counting
	call WindowCoordinateX2Counting
	call WindowCoordinateY1Counting
	call WindowCoordinateY2Counting
	;-------
	;copy 3xbuf to 2xbuf
	;----------------------------------
StartSend_ImageWindow_SCCB:
	;----------------
	mov r2,#04h
	mov r0,#WindowCountBufHeadAddr;; equ 30h
	Call Send_SCCB_to_OV7620
	;----------------
	call reply_PC
	;----------------
	;----------------to prepare get a frame image data
	clr ea
	;---------Reg12,Reg11,Reg16,Reg28
	Call SingleFrameCondition1SCCB
	mov r2,#04h
	mov r0,#WindowCountBufHeadAddr;; equ 30h
	Call Send_SCCB_to_OV7620
	;---------Reg20,Reg27
	Call SingleFrameCondition2SCCB
	mov r2,#02h
	mov r0,#WindowCountBufHeadAddr;; equ 30h
	Call Send_SCCB_to_OV7620
	;---------Reg13 to enable single frame output
	Call SingleFrameOutputEanbleSCCB
	mov r2,#01h
	mov r0,#WindowCountBufHeadAddr;; equ 30h
	mov IE,  #02h;     ea|x|eT2|es|eT1|eX1|eT0|eX0  // enable t0 only here 
setb ea	 ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! try
	Call Send_SCCB_to_OV7620
	;---------ov7620's delay is ? 
	setb ea	 ;!!
	;---------
WaitingForFrameFinished:
	nop
	nop
	nop
	nop
	nop
	;---------;maximum range :0000h~00ffh~01dfh: 480 row 
	;---------;window column range :0001h~(42h,43h):<=480 
windowColumnRangeCheck0:
	;{(x2-x1) at (40h,41h)}{(y2-y1) at (42h,43h)}
	;r4,r3: href line number	
	mov a,r4
	clr c 
	subb a,42h
   jc WaitingForFrameFinished
	mov a,r4
	cjne a,42h,InvalidEnd_MaximumRangeCheck
	mov a,r3
	clr c
	subb a,43h
	jc WaitingForFrameFinished
	cjne a,43h,InvalidEnd_MaximumRangeCheck	
	jmp validEnd_MaximumRangeCheck		
	;---------
InvalidEnd_MaximumRangeCheck:
	;-----
	;result is evil 
	;answer pc with "error"
	
	
	
	;-------------------------------
ValidEnd_MaximumRangeCheck:
	;result is well
	;answer pc with "ok"
	;-------------------------------
err_end_get_frame_image:
	mov a,#RecDataReadyAll;; equ 00h
	mov uart_re_status,a  ;;  data 0Bh
	;jmp end_get_frame_image
	;===============================
end_get_frame_image:
	ret
;-------------------------------------
;=====================================
;-------------------------------------	
SingleFrameCondition1SCCB:
	;------------Reg12=ach
	mov 30h,#12h;	
	mov 31h,#0ach;
	;------------Reg11=3fh
	mov 32h,#11h;
	mov 33h,#3fh;
	;------------Reg16=00h
	mov 34h,#16h;
	mov 35h,#00h;
	;------------Reg28=a0h
	mov 36h,#28h;
	mov 37h,#0a0h;
	;------------
	ret
;=====================================
SingleFrameCondition2SCCB:
	;------------Reg20=80h
	mov 30h,#20h;	
	mov 31h,#80h;
	;------------Reg27=e3h
	mov 32h,#27h;
	mov 33h,#0e3h;
	;------------
	ret
;=====================================
SingleFrameOutputEanbleSCCB:
	;------------Reg13=07h
	mov 30h,#13h;
	mov 31h,#07h;
	;------------	
	ret
;-------------------------------------
;=====================================
;-------------------------------------
reply_PC:
	mov a,#UartReBufHeadAddrPtr;; equ  20h
	mov r0,a     
	mov a,#UartTrBufHeadAddrPtr;; equ  10h	
	mov r1,a
	mov a,@r0	;command type
	mov @r1,a
	inc r0
	inc r1
	;----------------
	mov a,@r0	;amount
	mov @r1,a
	mov r2,a
	inc r0
	inc r1
	;----------------
	mov a,r2
	clr c 
	subb a,#0dh ; the amount is overflow as > 0ch
	jnc end_reply_PC
	;----------------
reply_PC_0:
	mov a,@r0	;data_1~data_2k
	mov @r1,a
	inc r0
	inc r1
	djnz r2,reply_PC_0
	;----------------
	mov a,#0ffh
	mov @r1,a
	;----------------
	mov a,#55h
	mov sbuf,a
	;----------------
end_reply_PC:
	ret
;-------------------------------------
;=====================================
;-------------------------------------
send_image_line_datum:	
		
	ret
;-------------------------------------
;=====================================
;-------------------------------------
WindowRangeDataToCheckBuf:
	mov r2,#08h
	mov r1,WindowCheckBufHeadAddr;; equ 40h
	mov r0,#UartReBufHeadAddrPtr;; equ 20h ;; cmmd type 
	inc r0 ;amount 
WRDTC00:
	inc r0 ;data1
	mov a,@r0
	mov r1,a
	inc r1
	djnz r2,WRDTC00
	ret
;-------------------------------------
;=====================================
;-------------------------------------	
WindowRangeCheckValueCounting:
	;==============X1:  dec -> hex
	mov 3eh,40h
	mov 3fh,41h
	;---------
	Call TransformDecToHex
	;---------
	mov 40h,3eh
	mov 41h,3fh
	;---------
	mov a,40h
	clr c
	subb a,#02h
	jc WRCVC01
	;---
WRCVC00:
	mov 40h,#01h ;;0140h==320D
	mov 41h,#40h
	jmp end_window_X1
	;---
WRCVC01:
	mov a,40h
	cjne a,#01h,end_window_X1
	mov a,41h
	clr c
	subb a,#41h
	jnc WRCVC00 	
	;---------
end_window_X1:
	;================X2  dec -> hex
	mov 3eh,42h
	mov 3fh,43h
	;---------
	Call TransformDecToHex
	;---------
	mov 42h,3eh
	mov 43h,3fh
	;---------
	mov a,42h
	clr c
	subb a,#01h
	jnc WRCVC01_X2
	;---
WRCVC00_X2:
	mov 42h,#01h ;;0141h==321D
	mov 43h,#41h
	jmp end_window_X2
	;---
WRCVC01_X2:
	mov a,42h
	clr c
	subb a,#03h
	jc WRCVC03_X2 
WRCVC02_X2:
	mov 42h,#02h ;;0280h==640D
	mov 43h,#80h
	jmp end_window_X2
	;---
WRCVC03_X2:
	mov a,42h
	cjne a,#02h,end_window_X2
	mov a,43h
	clr c
	subb a,#81h
	jnc WRCVC02_X2 	
	;---------
end_window_X2:
	;================
	;================Y1
	mov 3eh,44h
	mov 3fh,45h
	;---------
	Call TransformDecToHex
	;---------
	mov 44h,3eh
	mov 45h,3fh
	;---------
	mov a,44h
	clr c
	subb a,#01h
	jc WRCVC01_Y1
	;---
WRCVC00_Y1:
	mov 44h,#00h ;;00f0h==240D
	mov 45h,#0f0h
	jmp end_window_Y1
	;---
WRCVC01_Y1:
	mov a,45h
	clr c
	subb a,#0f1h
	jnc WRCVC00_Y1 	
	;---------
end_window_Y1:
	;================Y2
	mov 3eh,46h
	mov 3fh,47h
	;---------
	Call TransformDecToHex
	;---------
	mov 46h,3eh
	mov 47h,3fh
	;---------
	mov a,46h
	clr c
	subb a,#02h
	jnc WRCVC02_Y2
	;---
	mov a,46h
	cjne a,#00h,WRCVC01_Y2
	mov a,47h
	clr c
	subb a,#0f1h ;; 00f1h==241d
	jc WRCVC00_Y2
	jmp end_window_Y2 
	;---
WRCVC00_Y2:
	mov 46h,#00h ;;0141h==321D
	mov 47h,#0f1h
	jc end_window_Y2 
	;---
WRCVC01_Y2:
	mov a,47h
	clr c
	subb a,#0e1h
	jc end_window_Y2 
WRCVC02_Y2:
	mov 46h,#01h ;;01e0h==480D
	mov 47h,#0e0h
	jc end_window_Y2 
	;----
end_window_Y2:
	;================x2-x1 -->40h,41h
	clr c
	mov a,43h
	subb a,41h
	mov 41h,a
	mov a,42h
	subb a,40h
	mov 40h,a
	;================y2-y1 -->42h,43h
	clr c
	mov a,47h
	subb a,45h
	mov 43h,a
	mov a,46h
	subb a,44h
	mov 42h,a
	;=================
	ret
;-------------------------------------
;=====================================
;-------------------------------------	
GetWindowRangDatum:
	mov r2,#0ah
	mov r1,WindowCountBufHeadAddr;; equ 30h
	mov r0,#UartReBufHeadAddrPtr;; equ 20h ;; cmmd type 
	inc r0 ;amount 
GWRD00:
	inc r0 ;data1
	mov a,@r0
	mov r1,a
	inc r1
	djnz r2,GWRD00
	ret
;-------------------------------------
;=====================================
;-------------------------------------	
WindowCoordinateX1Counting:
	mov a,31h
	mov 3fh,a
	mov a,30h
	mov 3eh,a
	;---------
	Call TransformDecToHex
	Call Shipf_1_Bit_ToRight
	Call Shipf_1_Bit_ToRight
	;---------
	mov a,3fh
	clr c
	subb a,#51h;;50h=80
	jc WCDC01
	;---
	mov 3fh,#50h	
	;---
WCDC01:
	mov 30h,#17h; sccb cmmd : regist_17 :value range : 2fh~7eh
	mov a,3fh
	add a,#2eh;;base value of horizontal window left start point

⌨️ 快捷键说明

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