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

📄 camerasw.asm

📁 这是笔者早年开发的一款用单片机读摄象头图象数据的程序
💻 ASM
📖 第 1 页 / 共 2 页
字号:
	mov 31h,a
	ret
;-------------------------------------
;=====================================
;-------------------------------------	
WindowCoordinateX2Counting:
	;---------	
	mov 3fh,33h
	mov 3eh,32h
	;---------
	Call TransformDecToHex
	Call Shipf_1_Bit_ToRight
	Call Shipf_1_Bit_ToRight
	;---------
	mov a,3fh
	clr c
	subb a,#51h;;50h=80
	jnc WCDC01_X2
	;---
	mov 3fh,#51h	
	;---
WCDC01_X2:
	mov a,3fh
	clr c
	subb a,#0a1h
	jc WCDC02_X2
	mov 3fh,#0a0h
	;---
WCDC02_X2:
	mov 32h,#18h;register_18
	mov a,3fh
	add a,#2eh 
	mov 33h,a
	ret
;-------------------------------------
;=====================================
;-------------------------------------	
WindowCoordinateY1Counting:
	;---------	
	mov 3fh,35h
	mov 3eh,34h
	;---------
	Call TransformDecToHex
	Call Shipf_1_Bit_ToRight
	;---------
	mov a,3fh
	clr c
	subb a,#79h;;78h=120d
	jc WCDC01_Y1
	;---
	mov 3fh,#78h	
	;---
WCDC01_Y1:
	mov 34h,#19h
	mov a,3fh
	add a,#05h
	mov 35h,a
	;---------
	ret
;-------------------------------------
;=====================================
;-------------------------------------	
WindowCoordinateY2Counting:
	;---------	
	mov 3fh,37h
	mov 3eh,36h
	;---------
	Call TransformDecToHex
	Call Shipf_1_Bit_ToRight
	Call Shipf_1_Bit_ToRight
	;---------
	mov a,3fh
	clr c
	subb a,#79h;;78h=120d
	jnc WCDC01_Y2
	;---
	mov 3fh,#79h	
	;---
WCDC01_Y2:
	mov a,3fh
	clr c
	subb a,#0f1h ;#0f0h= +05h
	jc WCDC02_Y2
	mov 3fh,#0f0h
	;---
WCDC02_Y2:
	mov 36h,#1ah
	mov a,3fh
	add a,#05h
	mov 37h,a
	ret
;-------------------------------------
;=====================================
;-------------------------------------	
	;input : 3eh,3fh
	;output: 3eh,3fh
	;Dec. -->  Hex 
TransformDecToHex:
	;---
	mov a,3fh
	swap a
	anl a,#0fh
	mov r1,a
	;---
	mov a,3fh
	anl a,#0fh
THTD01:
	add a,#0ah
	djnz r1,THTD01
	mov 3fh,a
	mov r1,a
	mov a,3eh
	anl a,#0fh
	mov r0,a
	clr a
	mov r2,a
	mov a,r0
	jz THTD03
THTD02:
	clr c
	mov a,r1
	addc a,#64h
	mov r1,a
	mov a,r2
	addc a,#00h
	mov r2,a
	djnz r0,THTD02
THTD03:
	mov 3eh,r2;
	mov 3fh,r1
	;---
	ret
;-------------------------------------
;=====================================
;-------------------------------------
Shipf_1_Bit_ToRight:	
	clr c
	mov a,3eh
	rrc a
	mov 3eh,a
	mov a,3fh
	rrc a
	mov 3fh,a
	;---------
	ret
;-------------------------------------
;=====================================
;-------------------------------------
T0_Serve_VSYNC:
	;--------
	clr ea
End_New_Frame:
	;processing the frame end
	;--------
Start_New_Frame:	
	;-------;; y data address : dph||dpm||dpl
	mov r7,#00h;dph
	mov r6,#00h;dpm
	mov r5,#00h;;dpl
	;-------number of the HREF Line in a Frame ;max.=480 
	mov r4,#00h;;dph
	mov r3,#00h;;dpl
	;-------
	mov IE,  #03h;     ea|x|eT2|es|eT1|eX1|eT0|eX0  // enable int0 
	setb ea
	;------- 
End_T0_Serve:
	reti
;-------------------------------------
;=====================================
;-------------------------------------
Int0_serve_HREF: ;   0-->1 active 
	;-------
	clr ea
	push acc
	;;mov P0,#0ffh       ;setup p0 as input pin
	;;setb	Y_EN         ;Y_enable	 low active
	;;setb	PageAddr_OE  ;bit  p1.3 low active
	;setb	PageAddr_LE  ;PageAddr_LE=p3.5 active in low
	;Mov IE,#04h       ;only eable int1 	
	;-----row number increase count
	clr c 
	mov a,r3
	addc a,#01h
	mov r3,a    ;0001h~00ffh~01e0h: 480 row 
	mov a,r4
	addc a,#00h
	mov r4,a    ;<=01h
	;-----
Int0_serve_HREF_00:
/*
	cjne a,#01h,end_Int0_serve_HREF_00
	clr c
	mov b,r3
	mov a,#0dfh;;0e0h-1
	subb a,b
	jnc end_Int0_serve_HREF_00
	;-----
	mov a,#55h
	mov sbuf,a
	nop
	nop
	jmp End_Int0_serve_HREF;CompleteTheLastHREF_LineDatum
	;----
*/
end_Int0_serve_HREF_00:
	;----------	
Int0_serve_HREF_01:
	/*
	clr c
	mov a,R5
	addc a,#01h
	mov R5,a
	mov a,R6
	addc a,#00h
	mov R6,a
	mov a,R7
	addc a,#00h
	mov R7,a
	;----------
	*/
End_Int0_serve_HREF:
	mov P0,#0ffh
	setb Y_EN                    ;Y_enable	
	pop acc
	setb ea
	;----------
	Reti
;-------------------------------------
;=====================================
;-------------------------------------
Int1_serve_PCLK:    ;0-->1 active 
	;-----------23 instruction
	;clr ea
	;-----------
	push acc
	;---
	Mov P0,#0ffh
	clr Y_EN                    ;Y_enable	
	mov A,P0
	setb Y_EN                    ;Y_disable  
	;-----------
	clr 	PageAddr_LE    ;bit  p3.5 low active
	mov P0,R7
	setb 	PageAddr_LE    ;bit  p3.5 low active
	mov DPL,R5
	mov DPH,R6
	movx @DPTR,A
	;-----------
	clr c
	mov a,R5
	addc a,#01h
	mov R5,a
	mov a,R6
	addc a,#00h
	mov R6,a
	mov a,R7
	addc a,#00h
	mov R7,a
	;----------
	;mov P0,#0ffh
	;setb ea
	;----------
	pop acc
	reti
;******************************************************************************
;[55][aa][55][aa][commnd_type] [amount] [data #1][data #2]…[data #n] [checksum][ffh];
;	uart_buf_pointer data 08h ;r0 of bank1;
;	uart_checksum    data 09h ;r1 of bank1;
;	usrt_amount      data 0ah ;r2 of bank1;
;       uart_link_main   data 0bh ;r3 of bank1; 
;       link_cmmd:   00: uart receive communication fail
;                    01: uart receive communication finish
;                    02: ready for sending data communication by uart 
;	uart_buf_head    equ  20h
;	uart_data_long   data 21h;
;------------------------------------------------------------------------------
uart_re_init:
	mov uart_re_Status,#00h
	Ret
;-------------------------------------
uart_tr_init:
	mov uart_re_Status,#00h
	Ret
;-------------------------------------
Uart_Serve: 
	;-----------------
	push acc
	push b
	push psw
	mov  psw,#08h
	jnb  ri, goto_Send_to_Uart
	;-------1---------
	mov a,sbuf
	mov b,a
	clr ri
	;-----------------
uart_rec_st_0:
	mov a,uart_re_status
	cjne a,#00h,uart_rec_st_1
	mov a,b
	cjne a,#55h,goto_receive_err_quite
	mov a,#01h
	mov uart_re_status,a
	jmp End_uart_Serve
	;-------------------------	
uart_rec_st_1:
	mov a,uart_re_status
	cjne a,#01h,uart_rec_st_2
	mov a,b
	cjne a,#0AAh,goto_receive_err_quite
	mov a,#02h
	mov uart_re_status,a
	jmp End_uart_Serve
	;-------------------------	
uart_rec_st_2:
	mov a,uart_re_status
	cjne a,#02h,uart_rec_st_3
	mov a,b
	cjne a,#55h,goto_receive_err_quite
	mov a,#03h
	mov uart_re_status,a
	jmp End_uart_Serve
	;-------------------------
;==========================================
goto_Send_to_Uart:
	jmp Send_to_Uart
goto_receive_err_quite:
	jmp receive_err_quite
;==========================================
	;-------------------------	
uart_rec_st_3:
	mov a,uart_re_status
	cjne a,#03h,uart_rec_st_4
	mov a,b
	cjne a,#0AAh,goto_receive_err_quite
	mov a,#04h
	mov uart_re_status,a
	;--------	
	;re_buf_addr_ptr data 08h
	;re_checksum_counting data 09h
	;re_byte_number  data 0Ah
	;uart_re_status  data 0Bh
	mov a,#00h
	mov re_checksum_counting,a
	mov a,#UartReBufHeadAddrPtr ; at 20h
	mov re_buf_addr_ptr,a
	;--------
	jmp End_uart_Serve
   ;--------------------------
uart_rec_st_4:
	mov a,uart_re_status
	cjne a,#04h,uart_rec_st_5
	;-------
	mov a,#05h
	mov uart_re_status,a
	;-------
	mov a,b  ;receive uart command type ;first byte for checksum counting
	mov @r0,a;;;uart_buf_pointer,a;r0
	inc r0   ;;;uart_buf_pointer   ;r0
	;-------
	add a,re_checksum_counting
	mov re_checksum_counting,a
	;-------
	jmp End_uart_Serve
   ;=================
uart_rec_st_5:
	mov a,uart_re_status
	cjne a,#05h,uart_rec_st_6
	;-------
;;;uart_buf_pointer data 08h ;r0 of bank1
;;;uart_amount      data 0ah ;r2 of bank1
	mov a,#06h
	mov uart_re_status,a
	;-------
	mov a,b          ;the amount of datum 
	mov re_byte_number,a         ;counter of receiveing datum ; second byte for checksum counting
	mov @r0,a ;;;uart_buf_pointer,a
	inc r0    ;;;uart_buf_pointer;; at r0
	;-------
	add a,re_checksum_counting
	mov re_checksum_counting,a
	;-------
	jmp End_uart_Serve
   ;=================
uart_rec_st_6:
	mov a,uart_re_status
	cjne a,#06h,uart_rec_st_7
	;-------
	mov a,b
	mov @r0,a;;;@uart_buf_pointer,a
	inc r0   ;;;uart_buf_pointer
	;-------
	add a,re_checksum_counting
	mov re_checksum_counting,a
	;-------
	djnz re_byte_number,uart_rec_st_6_1
	mov a,#07h
	mov uart_re_status,a
	;-------
uart_rec_st_6_1:
	jmp End_uart_Serve
   ;-----------------------------
uart_rec_st_7:
	mov a,uart_re_status
	cjne a,#07h,receive_err_quite
	mov a,b
	cjne a,#0ffh,receive_err_quite
	;------------------;end receiving datum ,and ini receive status machine 	
	dec r0
	mov a,re_checksum_counting
	mov b,a
	mov a,@r0	
	cjne a,b,receive_err_quite
	mov uart_re_status,#RecDataFinished;==80h:rec datum finished	
	clr ea  ;close com int;!!!
	jmp End_uart_Serve
	;====================================
receive_err_quite:
	mov a,#UartReBufHeadAddrPtr; equ 20h
	mov re_buf_addr_ptr,a     ;; data at 08h
	mov a,#00h
	mov re_checksum_counting,a;; data at 09h
	mov re_byte_number,a      ;; data at 0Ah
	mov uart_re_status,a      ;; data at 0Bh
	jmp End_uart_Serve
	;===================================	
Send_to_Uart:
	;-----------------------------------
	;clr ti
	;mov a,#55h;
	;mov sbuf,a
	jnb ti,$
	clr ti
	;--------------------
	mov a,#0aah;
	mov sbuf,a
	jnb ti,$
	clr ti
	;--------------------
	clr ti
	mov a,#55h;
	mov sbuf,a
	jnb ti,$
	clr ti
	;--------------------
	mov a,#0aah;
	mov sbuf,a
	jnb ti,$
	clr ti
	;--------------------
uart_tr_st_0:
	;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
	;-----------
	mov a,#UartTrBufHeadAddrPtr;; equ 10h
	;mov tr_buf_addr_ptr,a;; data 0Ch	--
	mov r0,a
	mov a,@r0
	mov sbuf,a
	jnb ti,$
	clr ti
	;-----------
	cjne a,#CmmdType_SendImageLineDatum,uart_tr_st_1
	jmp SendImagLineDatum
	;-----------
uart_tr_st_1:
	inc r0	
	mov a,@r0
	mov sbuf,a
	jnb ti,$
	clr ti
	cjne a,#0ffh,uart_tr_st_1
	;-----------
	jmp End_uart_Serve
   ;--------------------------
	;===================================
SendImagLineDatum:
	inc r0	
	mov a,@r0
	mov sbuf,a;; amount 1
	mov r1,a
	jnb ti,$
	clr ti
	;-----------
	inc r0	
	mov a,@r0
	mov sbuf,a;; amount 2
	mov r2,a
	jnb ti,$
	clr ti
	;-----------	
	;send line datum of a frame image	
   ;--------------------------
	;===================================
End_uart_Serve: 
	clr ri
	clr ti
	;----------------
	pop psw
	pop b
	pop acc
	reti
;------------------------------------
;------------------------------------
;------------------------------------
;I2C bus operation
;------------------------------------
I2C_delay_CLK33MHz:
	;--------machine cycle=12/33=0.3636us
	;--------sccb baud rate 100KHz : delay=10us
	mov r3,#0ah
	;--------
I2C_delay0:
	;--------0.3636*50=18us delay : 55KHz 
	;nop
	;--------0.3636*40=15us delay : 66KHz 
	;nop	
	;--------0.3636*30=11us delay : 91KHz 
	nop
	djnz r3,I2C_delay0
	ret
;------------------------------------
START_BIT_I2C:	
	SETB I2C_SCL ;I2C start bit
	SETB I2C_SCL
	nop
	nop
	nop
	nop
	SETB I2C_SDA
	SETB I2C_SDA
	NOP
	NOP
	NOP
   NOP
   CLR  I2C_SDA
   CLR  I2C_SDA
   NOP
   NOP
	  call I2C_delay_CLK33MHz
   NOP
   NOP
   CLR  I2C_SCL
   CLR  I2C_SCL
   NOP
   NOP
	  call I2C_delay_CLK33MHz
   NOP
   NOP
	RET
   ;--------------------------
STOP_BIT_I2C: 
	CLR  I2C_SDA  ;I2C stop bit
	CLR  I2C_SDA
	nop
	nop
	nop
	nop
	SETB I2C_SCL  
	SETB I2C_SCL  
   NOP
	NOP
	  call I2C_delay_CLK33MHz
	NOP
	NOP
	SETB I2C_SDA
	SETB I2C_SDA
	NOP
	NOP
	  call I2C_delay_CLK33MHz
	NOP
	NOP
	RET
     ;--------------------------
   ;A<----DATA BYTE 
TX_BYTE_I2C:
	MOV R1,#08H;
TXB00:
	RLC A
	JNC TXB10
	SETB I2C_SDA
	SETB I2C_SDA
	SJMP TXB20
TXB10:
	CLR  I2C_SDA
	CLR  I2C_SDA
TXB20:
	NOP; ;>=250ns
	  call I2C_delay_CLK33MHz
	NOP
	SETB I2C_SCL
	SETB I2C_SCL
	NOP  ;>=4.7uS
	NOP
	  call I2C_delay_CLK33MHz
	NOP
	NOP	
	CLR  I2C_SCL
	CLR  I2C_SCL
	NOP
	NOP
	  call I2C_delay_CLK33MHz
	NOP
	DJNZ R1,TXB00
	ORL P1,#LogicRuler_I2C_SDA;02h
	NOP
	RET
	;--------------------------
RX_BYTE_I2C:
	ORL P1,#LogicRuler_I2C_SDA;02h
	MOV R1,#08H;
RXB00:
	SETB I2C_SCL
	SETB I2C_SCL
	nop
	  call I2C_delay_CLK33MHz
	nop
	JNB  I2C_SDA,RXB10
	jnb  i2c_sda,rxb10
	SETB C
	RLC A
	SJMP RXB20
RXB10:
	CLR C
	RLC A
RXB20:
	NOP
	NOP
	NOP
	NOP
	CLR I2C_SCL
	CLR I2C_SCL
	NOP
	NOP
	  call I2C_delay_CLK33MHz
	NOP
	NOP
	DJNZ R1,RXB00
	;A<----DATA BYTE
	nop
	nop
	RET
;------------------------------------              
RECEIVE_ACK:
	ORL P1,#LogicRuler_I2C_SDA;02h
	NOP
	  call I2C_delay_CLK33MHz
	NOP
	SETB I2C_SCL;
	NOP
	 call I2C_delay_CLK33MHz
	NOP
	JNB I2C_SDA,RAK30
	JNB I2C_SDA,RAK30
	JNB I2C_SDA,RAK30
	MOV A,#0FFH;
	SJMP RAK50
RAK30:  
	MOV A,#00H;
RAK50:  
	NOP
	NOP
	NOP
	NOP
	CLR I2C_SCL
	CLR I2C_SCL
	NOP
	NOP
	 call I2C_delay_CLK33MHz
	NOP
	NOP
	RET
;--------------------------------------
;--------------------------------------
;--------------------------------------
;--------------------------------------
;---------------------------------------------------------------------------------
end;ok

⌨️ 快捷键说明

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