Ðề tài: Bán PIC16F688
View Single Post
Old 30-05-2006, 11:29 AM   #13
dunghpc
Đệ tử 2 túi
 
Tham gia ngày: Nov 2005
Bài gửi: 39
:
Lat minh se cho ban gia mot so dong pic va cac IC khac, minh dang sua lai phan mem tim kiem, con CODE minh viet thi la cua cong ty khong the phat tan duoc, co gi minh chi trao doi kinh nghiem lam thoi, con CODE thi co le minh khong gui duoc. minh gui cho ban mot doan CODE doc ban phim PC tu 2 ngat ngoai nhe
Code:
LIST P=PIC18F2320, r=dec
	#include <P18f2320.inc>	
	#include <Comm.h>
	  __CONFIG  _CONFIG1H, _IESO_OFF_1H & _FSCM_OFF_1H & _HSPLL_OSC_1H
      __CONFIG  _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _BORV_20_2L
      __CONFIG  _CONFIG2H, _WDT_OFF_2H & _WDTPS_32K_2H
      __CONFIG  _CONFIG3H, _MCLRE_ON_3H & _PBAD_DIG_3H & _CCP2MX_C1_3H
      __CONFIG  _CONFIG4L, _LVP_OFF_4L & _STVR_OFF_4L

      __CONFIG  _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L
      __CONFIG  _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
      __CONFIG  _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L
      __CONFIG  _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
      __CONFIG  _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L
      __CONFIG  _CONFIG7H, _EBTRB_OFF_7H

;PortA
E	= 1	
RS	= 0
;PortC
Mor		= 0
Sdat 	= 4
Sclk	= 3
;PortB
;----------
aTris	= 0x0
bTris	= 0x3
cTris	= 0x80

	cblock	0x80
BitBuf,TxIn,TxOut,RxCnt,EeAddr
KeyBuf:2,KeyCnt,KeyParity,TabBuf
KeyTmp,DelayCnt,ms5Cnt,T0Cnt
LcdCnt,InLcd,OutLcd,TmpBuf
Cnt,Index,LcdBuf,DatOut
DatTmp,RxTmp,BufCnt,EeCnt
DaoCnt,KeyFlag
I2cBuf,I2cCnt,RamCnt,I2cCom,I2cLo,I2cHi
Time:8,StatusTmp,BinBuf,BcdBuf:2,StaTmp
Mouse,DeleCnt,fsr000
RxBuf:32
	endc

	cblock 0x0
Buffer:32
	endc
	cblock Buffer+33
MoocBuf,CntZero,StaBuf,BitCnt,CntOne
MorCnt,TichCnt,MorChr,MorseCnt
MorTmp,MorBit,StaWork,MorTime
	endc
;-------------
;-- StaWork --
fTB	= 0
fVB	= 1
fTT	= 2
;-------------
;EeProm
Tich = 129
;-------------
; RS-232
CR		= 13
LF		= 10
;-------------
;BitBuf
fStart	= 0
fRe		= 1
fBack	= 6
fUpdate	= 7
;---KeyFlag
fE0		= 0
fF0		= 1
fShift	= 2
;-------------
;--- MorBit --
fTrans	= 0
fStop	= 1
fSoTat	= 2
fTtiep	= 3
;StaBuf
fOne	= 0
fZero	= 1
fMooc	= 2
fSpace	= 3
;-------------
TxMin	= 0x40
TxMax	= 0x5f	
LcdMin	= 0x60
LcdMax	= 0x7f
;-------------
		org  0
		goto Init
		org  0x8
		goto HiInt
		org  0x18
		goto LowInt
;-----------------------
HiInt	
                          movf  Status,w,0
		movwf StatusTmp,1
		call  KeyTest
		movf  StatusTmp,w,1
		movwf status,0
Int0End	             bcf   intcon,int0if,0
		retfie fast
;----------------------
KeyTest	             btfsc BitBuf,fStart,1
		goto  StartOk
		btfsc portb,1,0
		return
		movlw 10
		movwf KeyCnt,1
		clrf  KeyParity,1
		bsf   BitBuf,fStart,1
		clrf  KeyBuf,1
		clrf  KeyBuf+1,1
		return
;-------------------
StartOk	            rrcf  KeyBuf+1,1,1
		rrcf  KeyBuf,1,1
		bcf   KeyBuf+1,1,1
		btfsc portb,1,0
		bsf   KeyBuf+1,1,1
		movf  KeyBuf+1,w,1
		xorwf KeyParity,1,1
		decfsz KeyCnt,1,1
		return
		bcf   BitBuf,fStart,1
		btfss KeyBuf+1,1,1
		return						; frame error
		btfsc KeyParity,1,1
		return						; carry error					
;--------------------
		movf  KeyBuf,w,1
		xorlw 0xE0
		btfss status,z,0
		goto  Key1
		bsf   KeyFlag,fE0,1
		return
Key1	             movf  KeyBuf,w,1
		xorlw 0xF0
		btfss status,z,0
		goto  Key2
		bsf   KeyFlag,fF0,1	; Key Released
		return
Key2	             btfsc KeyFlag,fE0,1
		goto  KeyUpDown
		btfss KeyFlag,fF0,1
		goto  KeyEnd
;--------------------
		bcf   KeyFlag,fShift,1
KeySw	             bcf   KeyFlag,fF0,1
		movf  KeyBuf,w,1
		xorlw 0x76
		btfsc status,z,0
		goto  KeyEsc
		btfsc MorBit,fStop,1
		goto  KeyShift

		movf  KeyBuf,w,1
		xorlw 0x83
		btfsc status,z,0
		goto  KeyF7
		movf  KeyBuf,w,1
		xorlw 0x4
		btfsc status,z,0
		goto  KeyF3
		movf  KeyBuf,w,1
		xorlw 0xc
		btfsc status,z,0
		goto  KeyF4
		movf  KeyBuf,w,1
		xorlw 0x5
		btfsc status,z,0
		goto  KeyF1
		movf  KeyBuf,w,1
		xorlw 0x6
		btfsc status,z,0
		goto  KeyF2
		movf  KeyBuf,w,1
		xorlw 0x3
		btfsc status,z,0
		goto  KeyF5
		movf  KeyBuf,w,1
		xorlw 0xb
		btfsc status,z,0
		goto  KeyF6
		movf  KeyBuf,w,1
		xorlw 0xa
		btfsc status,z,0
		goto  KeyF8
		movf  KeyBuf,w,1
		xorlw 0x1
		btfsc status,z,0
		goto  KeyF9
		movf  KeyBuf,w,1
		xorlw 0x9
		btfsc status,z,0
		goto  KeyF10
		movf  KeyBuf,w,1
		xorlw 0xd
		btfsc status,z,0
		goto  KeyTab

		movf  BufCnt,w,1
		xorlw 16
		btfsc status,z,0
		call  Line2
		movf  BufCnt,w,1
		sublw 31
		btfss status,c,0
		return
;-------
		movf  BufCnt,w,1
		addlw Buffer
		movwf fsr0l,0
		movf  KeyBuf,w,1
		btfss KeyFlag,fShift,1
		call  EeRead
		bcf   KeyFlag,fShift,1
		movwf KeyTmp,1
		sublw 126
		btfss status,c,0
		return
		movf  KeyTmp,w,1
		movwf indf0,0
		movf  indf0,w,0
		call  Byte2Lcd
		incf  BufCnt,1,1
		incf  Index,1,1
		btfsc MorBit,fTtiep,1
		goto  DemoMorse
		return
;-----------------------
Init:	            call  Bank0
		call  PortInit
		call  UsartInit
		call  T0Init
		call  LcdInit
		call  FileInit
		call  PwmInit
		call  LcdClr
		call  KeyF4
		clrf  BitBuf,1
		movlw 32
		movwf LcdCnt,1
		movlw Buffer
		movwf Mouse,1
		bsf   BitBuf,fUpdate,1
		call  Line1
		clrf  BufCnt,1
		clrf  RxCnt,1
		clrf  Index,1
		clrf  KeyFlag,1
		clrf  StaBuf,1
		clrf  MorBit,1
		clrf  portc,0
		clrf  StaWork,1
Loop	
		goto   Loop
;--------------------
FileInit                 bcf  eecon1,cfgs,0
		clrf  fsr0h,0
		clrf  fsr1h,0
		clrf  fsr2h,0
		clrf  ipr1,0
		clrf  pie1,0
		clrf  ipr2,0
		clrf  intcon3,0
		movlw 0xf0			; Tmr0 + Int0
		movwf intcon,0
		bsf   Rcon,Ipen,0
		movlw 0x80			; Int0  F0lling
		movwf intcon2,0
		movlw 0xf
		movwf adcon1,0
		return
;--------------------
T0Init	             movlw 0xC1			; 0.256ms
		movwf T0CON,0
		movlw 0xb1
		movwf T1CON,0
		return
;--------------------
PortInit                movlw aTris
		movwf trisa,0
		movlw bTris
		movwf trisb,0
		movlw cTris
		movwf trisc,0
		return
;--------------------
UsartInit              movlw 103	; 9600
		movwf SPBRG,0
		movlw 0x24	; TxEn+brgh
		movwf txsta,0
		movlw 0x90	; Spen+Cren
		movwf rcsta,0
		movlw TxMin
		movwf TxIn,1
		movwf TxOut,1
		return
;--------------------
PwmInit	             movlw 255
		movwf pr2,0
		movlw 0xc
		movwf ccp1con,0
		movlw 0x80
		movwf ccpr1l,0
		movlw 3
		movwf t2con,0
		return
;--------------------
Bank0	             movlb 0
		return
;----------------------
                          end

thay đổi nội dung bởi: falleaf, 30-05-2006 lúc 03:38 PM.
dunghpc vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn