Truncated match.
PICList
Thread
'Coding Problem'
1998\12\01@173225
by
Paul Phillips
|
Hi there (it's me again)
I've got another problem, I have written some code that scans 0-7 bits of
PORT B and checks to see if 0-7 bits are back low again.
(Code)
;Routine to handle a 4 digit code (password) using the 16F84
;Pass.asm using TASM.EXE -1684 -B
;Setup global variables
STATUS: .EQU $03
PORTA: .EQU $05
PORTB: .EQU $06
Z: .EQU 2
W: .EQU 0
C: .EQU 0
IN: .EQU 0 ;Stores current digit code
.ORG 4
.ORG 5
;Clear Ports A and B
clrf PORTA
clrf PORTB
bsf STATUS,5 ;Page 1
movlw %00000 ;Port A, all output
movwf PORTA
movlw %11111111 ;Port B, all output
movwf PORTB
bcf STATUS,5 ;Page 0
;Reset ports a and b
clrf PORTA
clrf PORTB
INIT:
bsf PORTA,0 ;Indicate to user that power is on
Call KeyScan ;Check to see if the user can
movlw IN ;(test only) This is the value of the digit entered
movwf PORTB ;(test only) Displays the digit to PORTB
Goto INIT ;Re-start
KeyScan:
movlw %00000000 ;Check to see if the user has entered a digit
xorwf PORTA,W
btfsc STATUS,Z
Goto KeyScan ;No, recheck
movlw PORTB ;Store the value
movwf IN ;(IN)
KeyCheck:
bcf STATUS,Z ;Check to see key has been released
clrf PORTA
movlw %00000000
xorwf PORTA,W
btfsc STATUS,Z
return ;Yes, key has been released
Goto KeyCheck ;No, still waiting for release, recheck
.END
The problem here is that I want to store the value in PORT B into variable
'IN' and display the value to PORT A, for testing purpose. This doe not
work, any comments would be greatefull.
Pul Phillips
spam_OUTPICTakeThisOuT
Colindale.demon.co.uk
1998\12\01@181352
by
Tony Nixon
Paul Phillips wrote:
>
> Hi there (it's me again)
>
> I've got another problem, I have written some code that scans 0-7 bits
Just as a quick look, you have defined 'IN' as the INDF register, so
your data will goto the register pointed to by the FSR, which could be
anywhere as it has not been initialised.
Try IN equ 0ch or similar.
You should be scanning portb for a keypress, not porta.
When reading portb, movlw PORTB will not work.
Try movf PORTB,w.
--
Best regards
Tony
Multimedia 16F84 Beginners PIC Tools.
http://www.picnpoke.com
Email .....picnpokeKILLspam
@spam@cdi.com.au
1998\12\01@185829
by
Regulus Berdin
|
Hi,
Please find below my comments.
Paul Phillips wrote:
{Quote hidden}>
> Hi there (it's me again)
>
> I've got another problem, I have written some code that scans 0-7 bits of
> PORT B and checks to see if 0-7 bits are back low again.
>
> (Code)
> ;Routine to handle a 4 digit code (password) using the 16F84
> ;Pass.asm using TASM.EXE -1684 -B
> ;Setup global variables
> STATUS: .EQU $03
> PORTA: .EQU $05
> PORTB: .EQU $06
> Z: .EQU 2
> W: .EQU 0
> C: .EQU 0
> IN: .EQU 0 ;Stores current digit code
Register IN should be mapped to a general purpose register not INDF.
Change this to:
IN EQU 0x0C
> .ORG 4
> .ORG 5
Program memory location 0 is the reset vector. While Location 4 is the
interrupt vector
Should be:
ORG 0
goto start
ORG 4
start:
> ;Clear Ports A and B
> clrf PORTA
> clrf PORTB
> bsf STATUS,5 ;Page 1
> movlw %00000 ;Port A, all output
> movwf PORTA
> movlw %11111111 ;Port B, all output ?????
> movwf PORTB
You had set PORTB as input while PORTA as OUTPUT . But below you
reversed your ports.
> bcf STATUS,5 ;Page 0
> ;Reset ports a and b
> clrf PORTA
> clrf PORTB
> INIT:
> bsf PORTA,0 ;Indicate to user that power is on
> Call KeyScan ;Check to see if the user can
> movlw IN ;(test only) This is the value of the digit entered
You confused movlw with movf. This line should be:
movf IN,W
> movwf PORTB ;(test only) Displays the digit to PORTB
> Goto INIT ;Re-start
> KeyScan:
> movlw %00000000 ;Check to see if the user has entered a digit
> xorwf PORTA,W
> btfsc STATUS,Z
Here is the PROBLEM. You checked PORTA instead of PORTB. PORTA is the
output.
It should be xorwf PORTB,W. One way to check if any input is held high
is:
movf PORTB,W
btfsc STATUS,Z
> Goto KeyScan ;No, recheck
> movlw PORTB ;Store the value
MOVLW instead of MOVF. This should be:
movf PORTB,W
> movwf IN ;(IN)
> KeyCheck:
> bcf STATUS,Z ;Check to see key has been released
> clrf PORTA
> movlw %00000000
> xorwf PORTA,W
Here also PORTA instead of PORTB.
> btfsc STATUS,Z
> return ;Yes, key has been released
> Goto KeyCheck ;No, still waiting for release, recheck
> .END
>
> The problem here is that I want to store the value in PORT B into variable
> 'IN' and display the value to PORT A, for testing purpose. This doe not
> work, any comments would be greatefull.
regards,
Reggie
1998\12\08@181400
by
Paul Phillips
part 0 651 bytes content-type:application/octet-stream;I've started using MPLAB (V4.0), currently i'm trying to write some code to
allow a user to enter a 5 digit number (code). When trying this using
MPLAB, it seems to work ok, but when I download the code to the PIC, does
not perform correct.
When the user enters the first digit, then increase the count. The problem
here, it never reaches the count rountine.
Any comments
Cheers
Paul Phillips
PIC
KILLspamColindale.demon.co.uk
Content-Type: application/octet-stream;
name="password.asm"
Content-Disposition: attachment;
filename="password.asm"
Attachment converted: wonderland:password.asm (????/----) (00020D9C)
1998\12\08@231856
by
Regulus Berdin
Paul Phillips wrote:
> I've started using MPLAB (V4.0), currently i'm trying to write some code to
> allow a user to enter a 5 digit number (code). When trying this using
> MPLAB, it seems to work ok, but when I download the code to the PIC, does
> not perform correct.
>
> When the user enters the first digit, then increase the count. The problem
> here, it never reaches the count rountine.
The problem you may have is debouncing. You did not include a routine
to
debounce your keys.
Also, KeyCount routine will stop incrementing COUNT reaches 0xFF.
KeyCount:
bsf PORTA,3
;Increase the key count
incfsz COUNT,W ;change the 2 lines to:
movwf COUNT ; incf COUNT,f
;first digit
movf COUNT,W
xorlw b'00000001'
btfsc STATUS,Z
bsf PORTA,3
;fifth digit
movf COUNT,W
xorlw b'00000101'
btfsc STATUS,Z
bcf PORTA,3
return
regards,
Reggie
1998\12\09@193304
by
Regulus Berdin
Paul Phillips wrote:
> what is debouncing (can you give a little example)
Debouncing is the art of reading a mechanical switch :).
When you press a switch the contacts may tend to bounce and the may not
be shorted continuously. Little glitches can appear on the input. This
can also happen when releasing (turning off).
Check out:
http://www.interstice.com/~sdattalo/technical/software/pic/debounce.html
Scott gives a technical explanation and some code on debouncing.
regards,
Reggie
1998\12\14@033810
by
Paul Phillips
1998\12\14@034436
by
Paul Phillips
Cheers for the input Wouter, I have tried the basic things I can think of.
I'm using a PIC TUTOR board, which I can write code using a text editor
which is compiled into hex via tasm.exe, I then used a program called
'Send.exe' to send the program to the PIC (via the PIC Tutor).
I have started use use the MPLAB (v4.0), where I have written some test
code (flasing an LED), compiled it to a hex file, used the 'Send.Exe'
program to send it to the PIC.
Can not get the thing to work at all, event the example code that comes
with MPLAB does not work!
Cheers
Paul Phillips
EraseMEPICspam_OUT
TakeThisOuTColindale.demon.co.uk
1998\12\14@123816
by
uter van ooijen / floortje hanneman
> Can not get the thing to work at all, event the example code that comes
> with MPLAB does not work!
Try to find out whether the problem is in
- the generation of the hex file (compare a hex file you generated with one
from the web?)
- in your programmer hardware (can you program in another way, take for
instance a simple programmer from the web and build it on a solderless
breadboard, or try to read a PIC with a known program)
- in your target hardware (get a programmed PIC from someone??)
suc6
Wouter.
1998\12\14@151905
by
Paul Phillips
|
Hi there
i'm using MPLAB (v4.0) and PIC Tutor Programmer/simulator. I can get MPLAB
to simulate my coding, I compile the code to HEX without any errors. I can
send the HEX to the PIC16F84 ok, but the PIC does not do anything, is this a
coding problem or MPLAB problem/setup.
Cheers
Pic
spam_OUTColindale.demon.co.uk
'________________________________________
;Project Name : Password.pjt
;Asm File : Password.asm
;Date : 10/12/1998
;Version : 1.0
;Purpose : To handle a 5 digit code via 7 line keypad
;Set-up
;_______________________________________________________________
;PORTA
;0 = OUT : Power ON
;1 = OUT : Key Pressed
;2 = OUT : First Digit Entered
;3 = OUT : 5th digit entered
;4 = OUT : <NOT USED>
;PORTB
;0 - 6 = IN : Input from keypad
;7 = Accept : Accept Code
#define page1 bsf status,5 ;Page 1
#define page0 bcf status,5 ;Page 0
status equ 0x03 ;Status
porta equ 0x05 ;Link to port a
portb equ 0x06 ;Link to port b
w equ 0 ;Working file
f equ 1 ;File
z equ 2
stable equ 0x08 ;Used for delay factor for debouncing inputs
in equ 0x09 ;Stores the port b digit
keywait equ 0x0A ;Counter for debouncing routine
digno equ 0x0B ;Digit number entered (upto five)
dig1 equ 0x0C ;Store digit 1
dig2 equ 0x0D ;Store digit 2
dig3 equ 0x0E ;Store digit 3
dig4 equ 0x0F ;Store digit 4
list p=16F84
#include p16f84.inc
org 4
org 5
;defaults
clrf porta
clrf portb
page1 ;Page 1
;set porta
movlw b'00000'
movwf porta
;port b
movlw b'1111111'
movwf portb
page0
;Reset variables
clrf keywait
clrf stable
clrf in
clrf digno
clrf dig1
clrf dig2
clrf dig3
clrf dig4
;Indicate to the outside world the the pic is running (port a,0)
bsf porta,0
begin:
call KeyScan ;Get input from port b
;inform the outside world that the user has realeased (port a,1)
bcf porta,1
;User has pressed a button (stored in 'in)
;Get the next digit number
call getnextdigit
goto begin
KeyScan:
;Check to see if the any of the bits are high
movlw b'00000000'
xorwf portb,W
btfsc status,z
Goto KeyScan ;No, recheck
clrf keywait
movf portb,w
;Store the value of port b
movwf in
;inform the outsite that a keypress event has occurred (port a,1)
bsf porta,1
debounce:
;wait x times to stable input
;increase the keywait by 1
incfsz keywait,f
;is keywait=stable
movf keywait,w
xorlw b'00001000'
btfss status,z
goto debounce ;no
KeyCheck:
;Wait to see if all bits are low
bcf status,z ;Clear status and PORTB
movlw b'00000000'
xorwf portb,w
btfsc status,z
return ;Yes, all bits are low
Goto KeyCheck ;no, wait until all bits are low
goto begin
getnextdigit:
;increase the digit count no by one
incfsz digno,f
;check for first digit
movf digno,w
xorlw d'1'
btfsc status,z
call dig_1
return
dig_1:
;inform other obhjects that the first digit has been entered
bsf porta,2
;store the value in dig1
movf in,w
movwf dig1
return
end
1998\12\14@170224
by
Reginald Neale
>Hi there
>
>i'm using MPLAB (v4.0) and PIC Tutor Programmer/simulator. I can get MPLAB
>to simulate my coding, I compile the code to HEX without any errors. I can
>send the HEX to the PIC16F84 ok, but the PIC does not do anything, is this a
>coding problem or MPLAB problem/setup.
>Cheers
Paul:
Just a long shot -- do you know the oscillator is working? What are you
using for oscillator component values?
Reg Neale
1998\12\14@170831
by
Tony Nixon
Paul Phillips wrote:
[snip]
> org 4
> org 5
> ;defaults
[snip]
The 16F84 starts code execution at Address 0000h. Perhaps you should
delete these Org's.
This may not matter if the PIC ROM has unprogrammed 3FFF in addresses
0000h - 0003h because that will execute as ADDLW FFh.
--
Best regards
Tony
Multimedia 16F84 Beginners PIC Tools.
http://www.picnpoke.com
Email @spam@picnpokeKILLspam
cdi.com.au
More... (looser matching)
- Last day of these posts
- In 1998
, 1999 only
- Today
- New search...