• slider image 514
  • slider image 516
  • slider image 517
  • slider image 518
  • slider image 519
:::


Browsing this Thread:   2 Anonymous Users






Re: PIC 16f877 驅動碼達,與按鍵!如何才能讓"蜂鳴器"叫~
#5
高級會員
高級會員


查看用戶資訊
呵~ 讓我猜猜, 該不是是景x學院的期末作業吧,
因為你的程式及問法, 跟我朋友的好像

多試試多Try Try

發表於: 2008/1/15 11:01
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC 16f877 驅動碼達,與按鍵!如何才能讓"蜂鳴器"叫~
#4
資深會員
資深會員


查看用戶資訊
你的問題跟之前被要求捐2000給世展會的一樣, 真不希望看到如此情況~
這樣的問題, 會回答的應該很少, 因為這是討論區, 討論必須是對等關係才能進行, 某人遇到問題, 另一人知道方法, 且感受某人已努力過, 所以互相分享, 不能只是丟個看起來完全沒有思考過的問題, 並附上落落長ㄟ程式請別人看, 我想應該沒有人願意呆在電腦前, 靜靜欣賞!!
你應丟出的問題, 應該是寫到什麼程度與何種瓶頸, 這樣回覆率才會增加, 且有意義, 除非你也是要交作業而已.
不然我現在寫的8kw 太陽能Inverter, 不也丟上來等答案呼?

發表於: 2008/1/15 8:40
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC 16f877 驅動碼達,與按鍵!如何才能讓"蜂鳴器"叫~
#3
新會員
新會員


查看用戶資訊
主程式只有這樣!!
硬體是實驗版的

峰鳴器只是實驗版上的!!已接好在蜂鳴器接在RA5/AN4

實驗版是Microport PIC_EVM Super 201


; 8 BITS A/D(VR) + LCD + PWM
;
LIST P=16F877, R=DEC
#INCLUDE P16F877.INC
CBLOCK 0X20
ENDC
;
; DEFINE RAM
;
CBLOCK
BCDBFH, BCDBFL,KYBUF
SPEED,TEMP,KEY_C
SECS,MINS,HRS,TEMP_MIN
W_BAK, STATUS_BAK ; back up RAM for w register


ENDC
;
alarm_seg equ TRISA
alarm_port equ PORTA
alarm_bit equ 5
;
ORG 0
NOP
GOTO MAIN
;
;

;---------------------------------------------------------------;
;
#INCLUDE <LCD.INC> ;
;
; Defines for I/O ports that provide LCD data & control ;
;
LCD_DATA equ PORTB ;
LCD_CNTL equ PORTB ;
;
RS equ 5 ; RS=PORTB,5 ;
E equ 4 ;
;
;===============================================================;
;
#INCLUDE <HX2BCD.INC>
#include <DLY2_5mS.INC>
;
;.................................
;---------------------------------------------------------------;
;
#INCLUDE <key4X4.asm> ;
PORT4X4 EQU PORTD ; keyboard is connected with portd ;
TRIS4X4 EQU TRISD ; set direction of port ;
;
;---------------------------------------------------------------;

;

MAIN:
call InitLCD
call clrLCD

;

;************************************************
;* - Initialize the A/D converter *
;* - Left justified *
;* - 1 analog channels, 0 references *
;* - Fosc/8 clock source *
;* - Channel 0 *
;* - Enable A/D *
;************************************************
;
; BANKSEL ADCON1 ; ADCON1 is in bank1
; MOVLW B'00000110' ; select left(0) justified (d7)
; 1 ch(AN0)/0 refs
; MOVWF ADCON1
;
; BANKSEL ADCON0
; MOVLW B'01000001' ; select Fosc/8(01), AN0(000)
; MOVWF ADCON0 ; a/d done(0), x(0), a/d ON(1)
;
BANKSEL TRISA
BCF TRISA,5
CLRF TRISD
MOVWF TRISA
;************************************************
;* - Initialize the CCP1 Module *
;* - Set the period to FFh *
;* - Make RC2 an output *
;* - Configure CCP1 for PWM (xxxx11xx) *
;* - Initialize Timer2 *
;* - 1:1 Postscale (x0000xxx) *
;* - 1:4 Prescale (xxxxxx01) *
;* - Enable the timer (xxxxx1xx) *
;************************************************

BANKSEL PR2
MOVLW H'FF'
MOVWF PR2
BCF TRISC,2
BANKSEL CCP1CON
MOVLW B'00001111'
MOVWF CCP1CON
MOVLW B'00000101'
MOVWF T2CON
CLRF SPEED ;reset speed to 0

CALL DLY2_5mS ; wait for input charge
MAIN1:
; BSF ADCON0,GO ; start a/d converting
MAIN2:
; BTFSC ADCON0,GO ; a/d convertion finished?
; GOTO MAIN2 ; no
;

call L2homeLCD
MOVLW 3
CALL movcurLCD ; move cursor right 3 positions

; MOVF ADRESH,W ; read a/d result ( high byte )
MOVF SPEED,W
CALL HX2BCD ; convert HEX to BCD
; results in BCDBFH/BCDBFL
MOVF BCDBFH,W ; output results to LCD
CALL putHexLCD
;
MOVF BCDBFL,W
CALL putHexLCD
MOVF SPEED,W
MOVWF CCPR1L ; Also in Duty cycle
CLRF KEY_C
CLRF TEMP
wait_key:
CALL KB4X4 ; read kyboard
BTFSC KYBUF,4 ; Key detected?
GOTO wait_key
MOVLW 10

SUBWF KYBUF,W ;number key?
BTFSS STATUS,C
GOTO NUMBER_KEY
;
GOTO wait_key
NUMBER_KEY:
MOVF KEY_C,W
BTFSC STATUS,Z
GOTO HUNDREDTH
SUBLW 1
BTFSC STATUS,Z
GOTO TENTH
MOVF TEMP,W
ADDWF KYBUF,W
BTFSC STATUS,C
GOTO OVER_FLOW
MOVWF SPEED
GOTO wait_ret
OVER_FLOW:
MOVLW 255
MOVWF SPEED
wait_ret:
CALL KB4X4
BTFSS KYBUF,4 ; KEY RELEASED?
GOTO wait_ret ; w=zero means key still pressed
GOTO MAIN2
HUNDREDTH:
INCF KEY_C
HUN_AGAIN:
MOVF KYBUF,W
BTFSC STATUS,Z
GOTO wait_release
; SUBLW 2
; BTFSC STATUS,C
; GOTO LESS_THAN_3
; MOVLW 2
; MOVWF KYBUF
LESS_THAN_3:
DECF KYBUF,F
MOVLW 100
ADDWF TEMP,F
BTFSS STATUS,C
GOTO HUN_AGAIN
MOVLW 255
MOVWF TEMP
GOTO HUN_AGAIN
TENTH:
INCF KEY_C
TEN_AGAIN:
MOVF KYBUF,W
BTFSC STATUS,Z
GOTO wait_release
DECF KYBUF,F
MOVLW 10
ADDWF TEMP,F
BTFSS STATUS,C
GOTO TEN_AGAIN
MOVLW 255
MOVWF TEMP
GOTO TEN_AGAIN
wait_release:
CALL KB4X4
BTFSS KYBUF,4 ; KEY RELEASED?
GOTO wait_release ; w=zero means key still pressed
CALL DLY2_5mS ; wait for moment
CALL DLY2_5mS ; wait for input charge
GOTO wait_key
;
;
;
END

發表於: 2008/1/10 19:55
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC 16f877 驅動碼達,與按鍵!如何才能讓"蜂鳴器"叫~
#2
版主
版主


查看用戶資訊
你的程式真的很長....不曉得要看多久才可以找到問題。
如果我寫的話,這 Buzzer 我會用 PWM 來推動 (CCP1 or CCP2) 先設定 PWM 的頻率等於 Buzzer 的協震頻率,利用 Timer 1 來做背景的計時與比較(比如設個 Buzzer Counter =20, 每次中斷時減一) 若Buzzer Counter >0 就啟動 PWM 的輸出讓 Buzzer 響起,若 = 0 就關閉 PWM 的輸出。至於要不要設定 Buzzer Counter 就由主程式決定,反正 Buzzer Counter =1 時就叫2mS, =50時就可以較 100mS,一但主程式設定後是由 Timer 1 的中斷去處理的,這樣程式就很簡單了。

要是有問題,打 0800-717-718 找楊雲樟先生問一下。

還有你的 Buzzer 是比較貴的已經內見震盪器的話,哪只要隨便找一隻 I/O 腳來推動,就不需用到 PWM 輸出了。

發表於: 2008/1/10 16:28
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


PIC 16f877 驅動碼達,與按鍵!如何才能讓"蜂鳴器"叫~
#1
新會員
新會員


查看用戶資訊
1:原型是按4x4按鍵三位數,讓馬達轉所輸入的數字,超過255,轉255(最高速)

2:現在想加一個功能就是,當輸入的數字超過180以上,蜂鳴器叫40ms,低於180不叫!

3:蜂鳴器接在RA5/AN4

主程式
-------------------
;
; 8 BITS A/D(VR) + LCD + PWM
;
LIST P=16F877, R=DEC
#INCLUDE P16F877.INC
CBLOCK 0X20
ENDC
;
; DEFINE RAM
;
CBLOCK
BCDBFH, BCDBFL,KYBUF
SPEED,TEMP,KEY_C
ENDC
;
ORG 0
NOP
GOTO MAIN
;
;

;---------------------------------------------------------------;
;
#INCLUDE <LCD.INC> ;
;
; Defines for I/O ports that provide LCD data & control ;
;
LCD_DATA equ PORTB ;
LCD_CNTL equ PORTB ;
;
RS equ 5 ; RS=PORTB,5 ;
E equ 4 ;
;
;===============================================================;
;
#INCLUDE <HX2BCD.INC>
#include <DLY2_5mS.INC>
;
;.................................
;---------------------------------------------------------------;
;
#INCLUDE <key4X4.asm> ;
PORT4X4 EQU PORTD ; keyboard is connected with portd ;
TRIS4X4 EQU TRISD ; set direction of port ;
;
;---------------------------------------------------------------;

;

MAIN:
call InitLCD
call clrLCD
;
;************************************************
;* - Initialize the A/D converter *
;* - Left justified *
;* - 1 analog channels, 0 references *
;* - Fosc/8 clock source *
;* - Channel 0 *
;* - Enable A/D *
;************************************************
;
; BANKSEL ADCON1 ; ADCON1 is in bank1
; MOVLW B'00001110' ; select left(0) justified (d7)
; 1 ch(AN0)/0 refs
; MOVWF ADCON1
;
; BANKSEL ADCON0
; MOVLW B'01000001' ; select Fosc/8(01), AN0(000)
; MOVWF ADCON0 ; a/d done(0), x(0), a/d ON(1)
;
;************************************************
;* - Initialize the CCP1 Module *
;* - Set the period to FFh *
;* - Make RC2 an output *
;* - Configure CCP1 for PWM (xxxx11xx) *
;* - Initialize Timer2 *
;* - 1:1 Postscale (x0000xxx) *
;* - 1:4 Prescale (xxxxxx01) *
;* - Enable the timer (xxxxx1xx) *
;************************************************

BANKSEL PR2
MOVLW H'FF'
MOVWF PR2
BCF TRISC,2
BANKSEL CCP1CON
MOVLW B'00001111'
MOVWF CCP1CON
MOVLW B'00000101'
MOVWF T2CON
CLRF SPEED ;reset speed to 0

CALL DLY2_5mS ; wait for input charge
MAIN1:
; BSF ADCON0,GO ; start a/d converting
MAIN2:
; BTFSC ADCON0,GO ; a/d convertion finished?
; GOTO MAIN2 ; no
;
call L2homeLCD
MOVLW 3
CALL movcurLCD ; move cursor right 3 positions

; MOVF ADRESH,W ; read a/d result ( high byte )
MOVF SPEED,W
CALL HX2BCD ; convert HEX to BCD
; results in BCDBFH/BCDBFL
MOVF BCDBFH,W ; output results to LCD
CALL putHexLCD
;
MOVF BCDBFL,W
CALL putHexLCD
MOVF SPEED,W
MOVWF CCPR1L ; Also in Duty cycle
CLRF KEY_C
CLRF TEMP
wait_key:
CALL KB4X4 ; read kyboard
BTFSC KYBUF,4 ; Key detected?
GOTO wait_key
MOVLW 10
SUBWF KYBUF,W ;number key?
BTFSS STATUS,C
GOTO NUMBER_KEY
;
GOTO wait_key
NUMBER_KEY:
MOVF KEY_C,W
BTFSC STATUS,Z
GOTO HUNDREDTH
SUBLW 1
BTFSC STATUS,Z
GOTO TENTH
MOVF TEMP,W
ADDWF KYBUF,W
BTFSC STATUS,C
GOTO OVER_FLOW
MOVWF SPEED
GOTO wait_ret
OVER_FLOW:
MOVLW 255
MOVWF SPEED
wait_ret:
CALL KB4X4
BTFSS KYBUF,4 ; KEY RELEASED?
GOTO wait_ret ; w=zero means key still pressed
GOTO MAIN2
HUNDREDTH:
INCF KEY_C
HUN_AGAIN:
MOVF KYBUF,W
BTFSC STATUS,Z
GOTO wait_release
; SUBLW 2
; BTFSC STATUS,C
; GOTO LESS_THAN_3
; MOVLW 2
; MOVWF KYBUF
LESS_THAN_3:
DECF KYBUF,F
MOVLW 100
ADDWF TEMP,F
BTFSS STATUS,C
GOTO HUN_AGAIN
MOVLW 255
MOVWF TEMP
GOTO HUN_AGAIN
TENTH:
INCF KEY_C
TEN_AGAIN:
MOVF KYBUF,W
BTFSC STATUS,Z
GOTO wait_release
DECF KYBUF,F
MOVLW 10
ADDWF TEMP,F
BTFSS STATUS,C
GOTO TEN_AGAIN
MOVLW 255
MOVWF TEMP
GOTO TEN_AGAIN
wait_release:
CALL KB4X4
BTFSS KYBUF,4 ; KEY RELEASED?
GOTO wait_release ; w=zero means key still pressed
CALL DLY2_5mS ; wait for moment
CALL DLY2_5mS ; wait for input charge
GOTO wait_key
;
;
;
END

-------------------------------------------------------------------------------



附程式

;---------------------------------------------------------------;
; ;
;#INCLUDE <LCD_klq.INC> ;
; ;
;; Defines for I/O ports that provide LCD data & control ;
; ;
;LCD_DATA equ PORTB ;
;LCD_CNTL equ PORTB ;
; ;
;RS equ 5 ; RS=PORTB,5 ;
;E equ 4 ;
; ;
;===============================================================;
;
;************************************************
;* LCD.INC *
;* is A modification of Microchip's *
;* sample program of workshop MCU201 *
;* The original program information *
;* is as the followings *
;************************************************
;* MCU201 Workshop *
;* Written by: Rodger Richey *
;* Principal Applications Engr. *
;* Microchip Technology Inc. *
;* Date: 1 April 1999 *
;* Revision: 1 *
;************************************************
;* Contains subroutines to control an external *
;* lcd panel in 4-bit mode. These routines *
;* were designed specifically for the panel on *
;* the MCU201 workshop demo board, but should *
;* work with other LCDs with a HD44780 type *
;* controller. *
;* Routines include: *
;* - InitLCD to initialize the LCD panel *
;* - putcLCD to write a character to LCD *
;* - SendCmd to write a command to LCD *
;* - clrLCD to clear the LCD display *
;* - L1homeLCD to return cursor to line 1 home*
;* - L2homeLCD to return cursor to line 2 home*
;************************************************
;
; define commands
;
; LCD Module commands
DISP_ON EQU 0x00C ; Display on
DISP_ON_C EQU 0x00E ; Display on, Cursor on
DISP_ON_B EQU 0x00F ; Display on, Cursor on, Blink cursor
DISP_OFF EQU 0x008 ; Display off
CLR_DISP EQU 0x001 ; Clear the Display
ENTRY_INC EQU 0x006 ;
ENTRY_INC_S EQU 0x007 ;
ENTRY_DEC EQU 0x004 ;
ENTRY_DEC_S EQU 0x005 ;
DD_RAM_ADDR EQU 0x080 ; Least Significant 7-bit are for address
DD_RAM_UL EQU 0x080 ; Upper Left coner of the Display

;
; define RAM
;
CBLOCK
Byte_LCD, Count, Count1, Count2, Posit_LCD, SystemFlag1
Byte, Byte1
ENDC
;
;
PUT_STRING MACRO STR_NO
movlw STR_NO-Msg1
call Message
ENDM

SET_CURSOR MACRO CUR_X,CUR_Y
movlw 0x80 + ((0x40*CUR_Y)+CUR_X)
call SendCmd
ENDM
;
;*******************************************************************
;* The LCD Module Subroutines *
;* Command sequence for 2 lines of 5x16 characters *
;*******************************************************************
InitLCD
bcf STATUS,RP0 ; Bank 0
bcf STATUS,RP1
clrf LCD_DATA ; Clear LCD data & control bits
bsf STATUS,RP0 ; Bank 1
movlw 0xc0 ; Initialize inputs/outputs for LCD
movwf LCD_DATA
btfsc PCON,NOT_POR ; Check to see if POR reset or other
goto InitLCDEnd

bcf STATUS,RP0 ; If POR reset occured, full init LCD
call LongDelay
movlw 0x02 ; Init for 4-bit interface
movwf LCD_DATA
bsf LCD_CNTL, E
bcf LCD_CNTL, E
call LongDelay

movlw b'00101000'
call SendCmd
movlw DISP_ON ; Turn display on
call SendCmd
movlw ENTRY_INC ; Configure cursor movement
call SendCmd
movlw DD_RAM_ADDR ; Set writes for display memory
call SendCmd

InitLCDEnd ; Always clear the LCD and set
bcf STATUS,RP0 ; the POR bit when exiting
call clrLCD
bsf STATUS,RP0
bsf PCON,NOT_POR
bcf STATUS,RP0
return

;*******************************************************************
;*SendChar - Sends character to LCD *
;*This routine splits the character into the upper and lower *
;*nibbles and sends them to the LCD, upper nibble first. *
;*******************************************************************
putcLCD
movwf Byte_LCD ; Save WREG in Byte variable
call Delay
swapf Byte_LCD,W ; Write upper nibble first
andlw 0x0f
movwf LCD_DATA
bsf LCD_CNTL, RS ; Set for data
bsf LCD_CNTL, E ; Clock nibble into LCD
bcf LCD_CNTL, E
movf Byte_LCD,W ; Write lower nibble last
andlw 0x0f
movwf LCD_DATA
bsf LCD_CNTL, RS ; Set for data
bsf LCD_CNTL, E ; Clock nibble into LCD
bcf LCD_CNTL, E
incf Posit_LCD ; move cursor right 1 position
return

;*******************************************************************
;* putDIGIT - put one digit (0 ~ F) *
;*******************************************************************
;
putDIGIT:
banksel Byte
bsf SystemFlag1,0 ; set Toggle bit for only oen digit!!
andlw 0x0f
goto Hex_Loop

;-------------------------------------------------------------------------------
;-- To put the HEX value to LCD Display ,,
;-- High nibble first than Low nibble
;-------------------------------------------------------------------------------
PutHexLCD
putHexLCD:
banksel Byte
bcf SystemFlag1,0 ; Clear Toggle bit !!

movwf Byte ; Save W Register !!

swapf Byte,W ; High nibble first !!

Hex_Loop
bcf SystemFlag1,1
andlw 0x0f ; Mask Bit 4 to 7
movwf Byte1
sublw .09
btfsc STATUS,C ; If W less than A (C=1) --> only add 30h
goto Add_W_30A

Add_W_37A
movlw 0x37
goto Show_High_Nibble
Add_W_30A
movlw 0x30
Show_High_Nibble

addwf Byte1,F ; The correct ASCII code for this char !!
call Delay
swapf Byte1,W ; Write upper nibble first

Write_LCD_Bus
andlw 0x0f
movwf LCD_DATA
bsf LCD_CNTL, RS ; Set for data
bsf LCD_CNTL, E ; Clock nibble into LCD
bcf LCD_CNTL, E
btfsc SystemFlag1,1
goto Test_Char_Finish

movf Byte1,W ; Write lower nibble last
bsf SystemFlag1,1
goto Write_LCD_Bus

Test_Char_Finish:
btfsc SystemFlag1,0
return ; If Toggle bit already be set to 1
; Otherwise !!
movf Byte,W ; Save to another Buffer -->
andlw 0x0f ; Mask Bit 4 to 7
bsf SystemFlag1,0
goto Hex_Loop ; Show next Char. -------->


SetCurLCD

return

;*******************************************************************
;* SendCmd - Sends command to LCD *
;* This routine splits the command into the upper and lower *
;* nibbles and sends them to the LCD, upper nibble first. *
;*******************************************************************
SendCmd
movwf Byte_LCD ; Save WREG in Byte variable
call Delay
swapf Byte_LCD,W ; Send upper nibble first
andlw 0x0f
movwf LCD_DATA
bcf LCD_CNTL,RS ; Clear for command
bsf LCD_CNTL,E ; Clock nibble into LCD
bcf LCD_CNTL,E
movf Byte_LCD,W ; Write lower nibble last
andlw 0x0f
movwf LCD_DATA
bcf LCD_CNTL,RS ; Clear for command
bsf LCD_CNTL,E ; Clock nibble into LCD
bcf LCD_CNTL,E
return

;*******************************************************************
;* clrLCD - Clear the contents of the LCD *
;*******************************************************************
clrLCD
movlw CLR_DISP ; Send the command to clear display
call SendCmd
return

;*******************************************************************
;* curonLCD - turn on cursor of the LCD *
;*******************************************************************
curonLCD
movlw DISP_ON_C ; Send the command to turn on cursor
call SendCmd
return

;*******************************************************************
;* curblkLCD - turn on and blink cursor of the LCD *
;*******************************************************************
curblkLCD
movlw DISP_ON_B ; Send the command to turn on and blink cursor
call SendCmd
return

;*******************************************************************
;* curoffLCD - turn off cursor of the LCD *
;*******************************************************************
curoffLCD
movlw DISP_ON ; Send the command to turn off cursor
call SendCmd
return

;*******************************************************************
;* movcurLCD - move cursor right for w position *
;*******************************************************************
movcurLCD
addwf Posit_LCD ; Send the command to turn off cursor
movf Posit_LCD,w
call SendCmd
return

;*******************************************************************
;* L1homeLCD - Moves the cursor to home position on Line 1 *
;*******************************************************************
L1homeLCD
movlw DD_RAM_ADDR|0x00 ; Send command to move cursor to
movwf Posit_LCD ; home position on line 1
call SendCmd
return

;*******************************************************************
;* L2homeLCD - Moves the cursor to home position on Line 2 *
;*******************************************************************
L2homeLCD
movlw DD_RAM_ADDR|0x40 ; Send command to move cursor to
movwf Posit_LCD ; home position on line 2
call SendCmd
return


;*******************************************************************
;* Delay - Generic LCD delay *
;* Since the microcontroller can not read the busy flag of the *
;* LCD, a specific delay needs to be executed between writes to *
;* the LCD. *
;*******************************************************************
Delay ; 2 cycles for call
clrf Count ; 1 cycle to clear counter variable
movlw 0x04
movwf Count1 ; ((256*3)-1)*4 ( modified for 16MHz )
Dloop
decfsz Count,f ; These two instructions provide a
goto Dloop ; (256 * 3) -1 cycle count
decfsz Count1
goto Dloop
return ; 2 cycles for return


;*******************************************************************
;* LongDelay - Generic long LCD delay *
;* POR delay for the LCD panel. *
;*******************************************************************
LongDelay
clrf Count
clrf Count1
;;; movlw 0x03
movlw .12 ; modified for 16MHz
movwf Count2
LDloop
decfsz Count,f
goto LDloop
decfsz Count1,f
goto LDloop
decfsz Count2,f
goto LDloop
return
;
;
-----------------------------------------------------------------------------------
;
;
KB4X4:
MOVLW H'FF' ;
MOVWF PORT4X4 ; turn off all pins
;
BANKSEL TRIS4X4 ; TRIS4X4 is in bank1
MOVLW B'00001111' ; b0~3=input, b4~7=output
MOVWF TRIS4X4 ;
BANKSEL PORT4X4 ; PORT4X4 is in bank0
;
MOVLW B'11101111' ; select RAW1 (0~3)
MOVWF PORT4X4
MOVLW H'10' ; preset KYBUF to be 0X10
BTFSS PORT4X4,0 ; key 0 ?
MOVLW 0
BTFSS PORT4X4,1 ; key 1 ?
MOVLW 1
BTFSS PORT4X4,2 ; key 2 ?
MOVLW 2
BTFSS PORT4X4,3 ; key 3 ?
MOVLW 3
MOVWF KYBUF ; store result
BTFSS KYBUF,4
GOTO KB4X4_1
;
BSF PORT4X4,4 ; turn off RAW1
BCF PORT4X4,5 ; turn on RAW2(4~7)
CALL KB4X4_DLY
;
BTFSS PORT4X4,0 ; key 4 ?
MOVLW 4
BTFSS PORT4X4,1 ; key 5 ?
MOVLW 5
BTFSS PORT4X4,2 ; key 6 ?
MOVLW 6
BTFSS PORT4X4,3 ; key 7 ?
MOVLW 7
MOVWF KYBUF ; store result
BTFSS KYBUF,4
GOTO KB4X4_1
;
BSF PORT4X4,5 ; turn off RAW2
BCF PORT4X4,6 ; turn on RAW3(8~B)
CALL KB4X4_DLY
;
BTFSS PORT4X4,0 ; key 8 ?
MOVLW 8
BTFSS PORT4X4,1 ; key 9 ?
MOVLW 9
BTFSS PORT4X4,2 ; key A ?
MOVLW H'A'
BTFSS PORT4X4,3 ; key B ?
MOVLW H'B'
MOVWF KYBUF ; store result
BTFSS KYBUF,4
GOTO KB4X4_1
;
BSF PORT4X4,6 ; turn off RAW3
BCF PORT4X4,7 ; turn on RAW4(C~F)
CALL KB4X4_DLY
;
BTFSS PORT4X4,0 ; key C ?
MOVLW H'C'
BTFSS PORT4X4,1 ; key D ?
MOVLW H'D'
BTFSS PORT4X4,2 ; key E ?
MOVLW H'E'
BTFSS PORT4X4,3 ; key F ?
MOVLW H'F'
MOVWF KYBUF ; store result
;
KB4X4_1:
BSF PORT4X4,7
RETURN
;
KB4X4_DLY: ; used for 16MHz CPU
NOP
NOP
NOP
RETURN
------------------------------------------------------------------------
;---------------------------------------------------------------;
; ;
;#INCLUDE <HX2BCD.INC> ;
; ;
;===============================================================;
;; ;
;; externally defined RAMs ( in main program) ;
;; ;
;; CBLOCK ;
;; DATBF1,DATBF2 ;
;; ENDC ;
;;..............................................................;
;
;
; HEX TO BCD CONVERTER
;
; convert w to BCDBFH/BCDBFL
;
;
; define RAM
;
CBLOCK
R0_HX2BCD
ENDC
;
;
HX2BCD:
MOVWF R0_HX2BCD ; temporary store w
CLRF BCDBFL
CLRF BCDBFH
;
HX2BCD1:
MOVLW 100
SUBWF R0_HX2BCD,W
SKPC
GOTO HX2BCD2 ; end of hundred convertion
MOVWF R0_HX2BCD
INCF BCDBFH
GOTO HX2BCD1
HX2BCD2:
MOVLW 10
SUBWF R0_HX2BCD,W
SKPC
GOTO HX2BCD3 ; end of hundred convertion
MOVWF R0_HX2BCD
MOVLW H'10'
ADDWF BCDBFL
GOTO HX2BCD2
HX2BCD3:
MOVF R0_HX2BCD,W
ADDWF BCDBFL
RETURN
---------------------------------------------------------------------------
;-----------------------------------------------;
; ;
; #INCLUDE <DLY2_5mS.INC> ;
; ;
;; delay 2.5 msec ;
;; for 16 MHz ;
;===============================================;
;
; define RAM
;
CBLOCK
R0_DLY2_5mS, R1_DLY2_5mS
ENDC
;
DLY2_5mS:
MOVLW 10 ; 10*250uS=2.5mS
MOVWF R1_DLY2_5mS
DLY2_5m1:
MOVLW 250 ; 250*1uS=250uS
MOVWF R0_DLY2_5mS
DLY2_5m2:
NOP ; 1ck
DECFSZ R0_DLY2_5mS ; 1ck
GOTO DLY2_5m2 ; 2ck(totaly 4 ck=1uS)
;
DECFSZ R1_DLY2_5mS
GOTO DLY2_5m1
RETURN
------------------------------------------------------------------------------
;-----------------------------------------------;
; ;
;#INCLUDE <DLY40mS.INC> ;
; ;
;; delay 40 msec ;
;; for 16 MHz ;
;===============================================;
;
; define RAM
;
CBLOCK
R0_DLY40mS, R1_DLY40mS
ENDC
;
DLY40mS:
MOVLW 200 ; 200*200uS=40mS
MOVWF R1_DLY40mS
DLY40mS1:
MOVLW 200 ; 200*1uS=200uS
MOVWF R0_DLY40mS
DLY40mS2:
NOP ; 1ck
DECFSZ R0_DLY40mS ; 1ck
GOTO DLY40mS2 ; 2ck(totaly 4 ck=1uS)
;
DECFSZ R1_DLY40mS
GOTO DLY40mS1
RETURN
---------------------------------------------------------------------------------

發表於: 2008/1/10 14:59
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------