本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
本人成功test到7846用8051仿真器,唔知有冇高手帮忙把它换成pic的呢?
p.s. pic instruction看过都不太明
$mod51
;connecting to uP
DCLK equ P1.7 ;clock
CS equ P1.6 ;low active enable
DIN equ P1.5 ;data input pin
BUSY equ P1.4
DOUT equ P1.3 ;data output pin
;input comand
;MEASURE_X equ 11011000B
;MEASURE_Y equ 10011000B
;*****************************************************************
;Code segment areas
;*****************************************************************
CSEG AT 0000H ;Code segment at 00H
ORG 00H
AJMP START ;Jump to start of program
ORG 1BH
AJMP Timer1 ;jump to timer1
ORG 30H
START:
MOV P1,#0FFH
CLR Busy_F
CLR Data_Ready_F
CLR Command_Ready_F
CLR Timer1_Ready_F
CLR Pos_Y_Measure_F
CLR Pos_X_Measure_F
; MOV TMOD,#20H ;8-bit timer mode (2)
; MOV TH1,#-10
; SETB TR1 ;Start timer 1
; SETB ET1 ;Enable timer 1 overflow interrupt
; SETB EA ;enable all interrupt
Loop:
; JNB Timer1_Ready_F,Loop_End
MOV Command_Buffer,#10011000B
SETB Pos_Y_Measure_F
ACALL Write_Command
MOV Command_Buffer,#11011000B
SETB Pos_X_Measure_F
ACALL Write_Command
; CLR Timer1_Ready_F
Loop_End:
SJMP Loop
;*****************************************************************
;Write command rountine
;*****************************************************************
Write_Command:
MOV A,Command_Buffer
MOV R0,#8
CLR DIN
CLR DCLK
SETB CS
CLR CS
Input_Loop:
MOV C,ACC.7
MOV DIN,C
CLR DCLK
SETB DCLK
RL A
DJNZ R0,Input_Loop
Input_Loop_End:
MOV Command_Buffer,A
JB Busy_F,$
MOV R0,#8
Output_Loop:
MOV C,DOUT
MOV ACC.7,C
CLR DCLK
SETB DCLK
RL A
DJNZ R0,Output_Loop
Output_Loop_End:
MOV Data_Buffer,A
JB Pos_X_Measure_F,Data_store_X
JB Pos_Y_Measure_F,Data_store_Y
Data_store_X:
MOV Data_Buffer_X,Data_Buffer
CLR Pos_X_Measure_F
SJMP Write_Command_End
Data_store_Y:
MOV Data_Buffer_Y,Data_Buffer
CLR Pos_Y_Measure_F
Write_Command_End:
RET
;*****************************************************************
;timer1 counting rountine
;*****************************************************************
Timer1:
PUSH PSW
PUSH ACC
SETB Timer1_Ready_F
Timer1_End:
POP ACC
POP PSW
RETI
;*****************************************************************
;Data segment areas
;*****************************************************************
DSEG AT 30H
Command_Buffer: DS 8
Data_Buffer: DS 8
Data_Buffer_X: DS 8
Data_Buffer_Y: DS 8
;*****************************************************************
;Flag bit segment areas
;*****************************************************************
BSEG AT 00H
Busy_F: DBIT 1 ;1=busy
Data_Ready_F: DBIT 1 ;1=Data ready
Command_Ready_F: DBIT 1 ;1=command ready
Timer1_Ready_F: DBIT 1 ;1=timer ready
Pos_X_Measure_F: DBIT 1
Pos_Y_Measure_F: DBIT 1
;*****************************************************************
;End of Program
;*****************************************************************
END |
|