Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

i cant read input of the PIC

Status
Not open for further replies.

scorpionss22

Full Member level 2
Joined
Jan 8, 2004
Messages
146
Helped
4
Reputation
8
Reaction score
1
Trophy points
1,298
Activity points
1,284
Hi all
i thought my self expert in Programming PIC untill i have this problem

i write a pic code in assembly and i test it in MBLAP i made Simulation and
it work excellent
but after i download if to PIC i am shocked its not working:cry:

i tried alot But nothing happend

i am thinking that the pic cant read the input Because i made i simple
program to test if its read the input but i found that it didnt read the in put
iam using mBLAP 7.5 and TK3 programmer with XPhome Edition
Can You help
Thanks For Cooperation

list p=16F84A
#include P16F84A.inc

SWITCH EQU 20
COUNTER EQU 21
CODEE EQU 22
CSTART EQU 23 ; B'10100111'
WORK EQU 24
IRREG EQU 25
CONFIRM EQU 26
count1 EQU 27
count2 EQU 28
BOUNCE1 EQU 29
BOUNCE2 EQU 2a
COUNTER1 EQU 2b

ORG 00
;BCF 03,6
BSF 03,5 ;BANK 01
;MOVLW 0x06 ; Configure all pins
;MOVWF ADCON1 ; as digital inputs
;MOVLW 0xCF ; Value used to
; initialize data
; direction

; BCF OPTION_REG,3
MOVLW 0FF ;MAKE PORT B INPUT
MOVWF 06
BCF 05,0 ;MAKE RAO OUTPUT FOR A INDECATOR
BCF 05,1 ;MAKE RA1 OUTPUT FOR A IR LED
BCF 03,5 ;BANK 00
Clrf PORTA
bsf portA,0

GOTO STARTER

;------------------ Table to know which key is pressed -----------------------------------------

SwTable MOVF COUNTER,W
ADDWF PCL
NOP
GOTO DeB0
GOTO DeB1
GOTO DeB2
GOTO DeB3
GOTO DeB4
GOTO DeB5
GOTO DeB6
GOTO DeB7

;------------------ Table to Encode The Switch ------------------------------------------------

CTable bcf 05,0
ADDWF PCL,F
NOP
RETLW B'01010101' ;CODE FOR ZERO
RETLW B'00110011' ;CODE FOR ONE
RETLW B'11000111' ;CODE FOR TWO
RETLW B'10100111' ;CODE FOR THREE
RETLW B'10100111' ;CODE FOR FOUR
RETLW B'10100111' ;CODE FOR FIVE
RETLW B'10100111' ;CODE FOR SIX
RETLW B'10100111' ;CODE FOR RECORD

;----------------- Start testing if any key is pressed --------------------------------------------
STARTER MOVLW B'10100111'
MOVWF CSTART
START CAll Delay100mS
MOVLW 00
Btfss 06,0
;BCF STATUS,Z
;XORWF PORTB,W ;TEST IF ANY KEY PRESSED
;BTFSC STATUS,Z
GOTO START ;NOT PRESSED

;----------------- After pressing any key --------------------------------------------------------
Call Delay100mS
Call Delay100mS
Call Delay100mS
Call Delay100mS
Call Delay100mS
movlw 01
xorwf 05
Goto Start


;MOVF PORTB ;COPY THE PORT TO TEST KEY
;MOVWF SWITCH ;RAM REGISTER
BCF STATUS,C
MOVLW 08
MOVWF COUNTER
ROTATE BCF STATUS,C
RLF SWITCH
BTFSC STATUS,C
GOTO SwTable
DECFSZ COUNTER
GOTO ROTATE

GOTO START

;-----------------ROUTEN TO SEND DATA -------------------------------------------------

SEND BCF STATUS,C
MOVLW 08
MOVWF COUNTER1
CHECK RLF WORK
BTFSS STATUS,C
GOTO ZERO
GOTO ONE
RESUME DECFSZ COUNTER1
GOTO CHECK
RETURN

;----------------- SEND ONE -------------------------------------------------------------------

ONE MOVLW D'40' ;13 Micro Second HALF OF THE WAVE(1040Us
MOVWF IRREG
SEET BSF PORTA,1
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BCF PORTA,1
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
DECFSZ IRREG
GOTO SEET
CALL Delay100mS
GOTO RESUME

;----------------- SEND ZERO -------------------------------------------------------------------

ZERO MOVLW D'80' ;13 Micro Second HALF OF THE WAVE(2080Us
MOVWF IRREG
SETT BSF PORTA,1
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BCF PORTA,1
NOP
NOP
NOP
NOP
NOP
NOP
DECFSZ IRREG
GOTO SETT
CALL Delay100mS

GOTO RESUME

;---------------DEBOUNCE SWITCH 0 ----------------------------------------------------------

DeB0 CLRF BOUNCE1
MOVLW D'255'
MOVWF BOUNCE2
DEBOUNCE0 BCF STATUS,C ;1uS
BTFSS PORTB,0 ;2uS
GOTO START ;
INCF BOUNCE1 ;1uS
BTFSS BOUNCE1,7 ;1uS
GOTO DEBOUNCE0 ;2uS
CLRF BOUNCE1
INCF BOUNCE2 ;1uS
MOVLW D'255' ;1uS
XORWF BOUNCE2,W ;1uS
BTFSS STATUS,Z ;1uS
GOTO DEBOUNCE0 ;2uS
CALL Delay100mS
UPRB0 BTFSC PORTB,0
GOTO UPRB0
BSF 05,0 ;Indicator ON
GOTO USECODE
;BTFSS CONFIRM,0
;GOTO BYPASS
;BSF CONFIRM,1
;BYPASS BCF CONFIRM,0
;GOTO USECODE

;---------------DEBOUNCE SWITCH 1 ----------------------------------------------------------

DeB1 CLRF BOUNCE1
MOVLW D'255'
MOVWF BOUNCE2
DEBOUNCE1 BCF STATUS,C ;1uS
BTFSS PORTB,1 ;2uS
GOTO START ;
INCF BOUNCE1 ;1uS
BTFSS BOUNCE1,7 ;1uS
GOTO DEBOUNCE1 ;2uS
CLRF BOUNCE1
INCF BOUNCE2 ;1uS
MOVLW D'255' ;1uS
XORWF BOUNCE2,W ;1uS
BTFSS STATUS,Z ;1uS
GOTO DEBOUNCE1 ;2uS
CALL Delay100mS
UPRB1 BTFSC PORTB,1
GOTO UPRB1

BSF PORTA,0 ;Indicator ON
;BTFSS CONFIRM,0
;GOTO BYPASS
;BSF CONFIRM,1
;BYPASS BCF CONFIRM,0
GOTO USECODE

;---------------DEBOUNCE SWITCH 2 ----------------------------------------------------------

DeB2 CLRF BOUNCE1
MOVLW D'255'
MOVWF BOUNCE2
DEBOUNCE2 BCF STATUS,C ;1uS
BTFSS PORTB,2 ;2uS
GOTO START ;
INCF BOUNCE1 ;1uS
BTFSS BOUNCE1,7 ;1uS
GOTO DEBOUNCE2 ;2uS
CLRF BOUNCE1
INCF BOUNCE2 ;1uS
CLRF BOUNCE1
MOVLW D'255' ;1uS
XORWF BOUNCE2,W ;1uS
BTFSS STATUS,Z ;1uS
GOTO DEBOUNCE2 ;2uS
CALL Delay100mS
UPRB2 BTFSC PORTB,2
GOTO UPRB2

BSF PORTA,0 ;Indicator ON
;BTFSS CONFIRM,0
;GOTO BYPASS
;BSF CONFIRM,1
;BYPASS BCF CONFIRM,0
GOTO USECODE

;---------------DEBOUNCE SWITCH 3 ----------------------------------------------------------

DeB3 CLRF BOUNCE1
MOVLW D'255'
MOVWF BOUNCE2
DEBOUNCE3 BCF STATUS,C ;1uS
BTFSS PORTB,3 ;2uS
GOTO START ;
INCF BOUNCE1 ;1uS
BTFSS BOUNCE1,7 ;1uS
GOTO DEBOUNCE3 ;2uS
CLRF BOUNCE1
INCF BOUNCE2 ;1uS
MOVLW D'255' ;1uS
XORWF BOUNCE2,W ;1uS
BTFSS STATUS,Z ;1uS
GOTO DEBOUNCE3 ;2uS

CALL Delay100mS
UPRB3 BTFSC PORTB,3
GOTO UPRB3

BSF PORTA,0 ;Indicator ON
;BTFSS CONFIRM,0
;GOTO BYPASS
;BSF CONFIRM,1
;BYPASS BCF CONFIRM,0
GOTO USECODE

;---------------DEBOUNCE SWITCH 4 ----------------------------------------------------------

DeB4 CLRF BOUNCE1
MOVLW D'255'
MOVWF BOUNCE2
DEBOUNCE4 BCF STATUS,C ;1uS
BTFSS PORTB,4 ;2uS
GOTO START ;
INCF BOUNCE1 ;1uS
BTFSS BOUNCE1,7 ;1uS
GOTO DEBOUNCE4 ;2uS
CLRF BOUNCE1
INCF BOUNCE2 ;1uS
MOVLW D'255' ;1uS
XORWF BOUNCE2,W ;1uS
BTFSS STATUS,Z ;1uS
GOTO DEBOUNCE4 ;2uS

CALL Delay100mS
UPRB4 BTFSC PORTB,4
GOTO UPRB4

BSF PORTA,0 ;Indicator ON
;BTFSS CONFIRM,0
;GOTO BYPASS
;BSF CONFIRM,1
;BYPASS BCF CONFIRM,0
GOTO USECODE

;---------------DEBOUNCE SWITCH 5 ----------------------------------------------------------

DeB5 CLRF BOUNCE1
MOVLW D'255'
MOVWF BOUNCE2
DEBOUNCE5 BCF STATUS,C ;1uS
BTFSS PORTB,5 ;2uS
GOTO START ;
CLRF BOUNCE1
INCF BOUNCE1 ;1uS
BTFSS BOUNCE1,7 ;1uS
GOTO DEBOUNCE5 ;2uS
INCF BOUNCE2 ;1uS
MOVLW D'255' ;1uS
XORWF BOUNCE2,W ;1uS
BTFSS STATUS,Z ;1uS
GOTO DEBOUNCE5 ;2uS

CALL Delay100mS
UPRB5 BTFSC PORTB,5
GOTO UPRB5

BSF PORTA,0 ;Indicator ON
;BTFSS CONFIRM,0
;GOTO BYPASS
;BSF CONFIRM,1
;BYPASS BCF CONFIRM,0
GOTO USECODE

;---------------DEBOUNCE SWITCH 6 ----------------------------------------------------------

DeB6 CLRF BOUNCE1
MOVLW D'255'
MOVWF BOUNCE2
DEBOUNCE6 BCF STATUS,C ;1uS
BTFSS PORTB,6 ;2uS
GOTO START ;
INCF BOUNCE1 ;1uS
BTFSS BOUNCE1,7 ;1uS
GOTO DEBOUNCE6 ;2uS
CLRF BOUNCE1
INCF BOUNCE2 ;1uS
MOVLW D'255' ;1uS
XORWF BOUNCE2,W ;1uS
BTFSS STATUS,Z ;1uS
GOTO DEBOUNCE6 ;2uS

CALL Delay100mS
UPRB6 BTFSC PORTB,6
GOTO UPRB6

BSF PORTA,0 ;Indicator ON
;BTFSS CONFIRM,0
;GOTO BYPASS
;BSF CONFIRM,1
;BYPASS BCF CONFIRM,0
GOTO USECODE

;---------------DEBOUNCE SWITCH 7 ----------------------------------------------------------

DeB7 CLRF BOUNCE1
MOVLW D'255'
MOVWF BOUNCE2
DEBOUNCE7 BCF STATUS,C ;1uS
BTFSS PORTB,7 ;2uS
GOTO START ;
INCF BOUNCE1 ;1uS
BTFSS BOUNCE1,7 ;1uS
GOTO DEBOUNCE7 ;2uS
CLRF BOUNCE1
INCF BOUNCE2 ;1uS
MOVLW D'255' ;1uS
XORWF BOUNCE2,W ;1uS
BTFSS STATUS,Z ;1uS
GOTO DEBOUNCE7 ;2uS

CALL Delay100mS
UPRB7 BTFSC PORTB,7
GOTO UPRB7

BSF PORTA,0 ;Indicator ON
GOTO USECODE
;BTFSC CONFIRM,0
;GOTO START
;MOVLW B’10101011’ ;CODE TO RECORD PASSWORD
;MOVWF IRREG
;BSF CONFIRM,0
;MOVWF CODE
;MOVF CSTART
;MOVWF WORK
;CALL SEND
;MOVF IRREG
;MOVWF WORK
;CALL SEND
;BTFSS CONFIRM,0
;BCF PORTA,0
;GOTO START

;----------------- FETCH THE CODE TO SEND --------------------------------------------

USECODE MOVF COUNTER,w
CALL CTable
MOVWF CODEE
MOVF CSTART,w
MOVWF WORK
CALL SEND
CALL Delay100mS
MOVF CODEE,w
MOVWF WORK
CALL SEND
;BTFSS CONFIRM,1
BCF PORTA,0
GOTO START


;------ 100 mS delay at 4 MHz----------------------------------------

Delay100mS

movlw .130
movwf count1
movlw .221
movwf count2

dloop1 decfsz count2,f
goto dloop1
decfsz count1,f
goto dloop1
retlw 0x00
END
 

have you used pull-ups?
 

i am Using Port B as input why should i use Pull up
I connect the RB0 through R(10K) to Ground When i press The Buttom The 5Vdc Come to input
 

i may not be of more help to you, but once i had got the same problem. my logic was reverse. i was using switch between pin and ground. pullup resistor of 10k solved my probelm........anyway bol
 

I have build a ICD2 then its easily to debug hard- and software
 

i have made many simple code befor and was working fine but now i dont know what is the problem
 

What is the voltage on input an while you push the switch ?
Have you set off the internal pull up resistors?

It’s a better way to use a resistor to de + 5 and a switch to the ground.

Added after 5 minutes:

movwf TRISB
movlw b'10000000' ; Disable PORTB week pullup resistors
movwf OPTION_REG

Added after 18 minutes:

 

hi are would u plz guide me to build this ICD
from where i can get the schematic
tell me all the details plz
thanks for ur cooperation
 

the guys told the right thing about the weak pullups for ICD u can use microchip forum for the circuit one more thing is i will suggets is to use a c complier with mplab for software development ccs s is best
 

Hi Scorpionss22

soooo.... you are using external pull-downs huh? well i think it`s ok. could you post your circuit, so we can check it? have you checked also the config bits?

aaaaannnnd....

checking your code....(very lightly sorry!)

you send 0xFF to TRISB ok!

but there are many instructions commented...

the part I dont catch is after the (after the key is pressed)
you have commented the read of the portB to the SWITCH register
and after that! you are rotating the SWITCH register!
sorry I dind`t check all your code... And I don't get, why you comment the port read, but not the SWITCH rotation!!!

well... about the ICD just check it here at edaboard! there are many post, circuits. etc...

cheers!
 

thank u all for u r reply i discovered what is wrong
in MBLAP setting the Hex format
and its solved now the code is working fine thanks
friends
but remening the ICD as Kurenai_ryu said there is alot of circiut in EDAboard for icd so which one i have to choose

thanks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top