Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Switch reading problem.

Status
Not open for further replies.

is0lated

New Member
I'm having a bit of a problem with some code I've written for the 16f84a, the program is designed to read input from 2 switches and turn an LED on or off.
The problem that I'm having is that, although it runs fine in MPLAB simulator and I've tried modifying the code to force it to go through the turning on and off of an LED but whenever I program the PIC one of the LEDs stays off for about a second on turn on then flashes.

It's running off of a 4Mhz XT oscillator, WDT is off, Code protect is off, and power on timer is off. (This is done through the program I use to program the PIC.)

I'm kind of new to Micro controllers so there's probably an obvious problem somewhere. Any feedback would be great.
 

Attachments

  • TEST 6.ASM
    2.1 KB · Views: 122
I'm having a bit of a problem with some code I've written for the 16f84a, the program is designed to read input from 2 switches and turn an LED on or off.
The problem that I'm having is that, although it runs fine in MPLAB simulator and I've tried modifying the code to force it to go through the turning on and off of an LED but whenever I program the PIC one of the LEDs stays off for about a second on turn on then flashes.

It's running off of a 4Mhz XT oscillator, WDT is off, Code protect is off, and power on timer is off. (This is done through the program I use to program the PIC.)

I'm kind of new to Micro controllers so there's probably an obvious problem somewhere. Any feedback would be great.

hi,
Running the program in the Oshonsoft Sim, it does the same action as you describe... flashing LED..

Which assembler are you using.?

I'll check it thru for you.
 
hi,
Your COUNT registers are located in the RESERVED area, the user regs start at 0x0C.
Move them to 0xc and 0x0d

The switches on PORTB.1 and .2 are being tested for a LOW state.
ie; If Low then do Turn R or L, so I assume you have pullup resistors on the pins and the switch pulls the pin low
BUT:
PORTB.2 is set as an output.! ,so the test always succeeds.

Make these changes and if any more problems, come back..:)
 
hi
I tried to update the last post by EDITING.. but now a 15 minute limit applies to editing a post.!!!

Comment ref your progarm.

By using a GOTO after the first switch test if the switch is closed the second switch never gets tested.!

Consider using a CALL to .... R and L with a RETURN at the end of the R and L routines.
 
Hi
Need to change:

Start movlw 0x03 ;turn on both motors
movwf PORTA ;do above

Change the above line to movwf PORTB


btfss PORTB,1 ;Check the left sensor
Change above line to PORTB,0
goto TurnRight ;If the left sensor is on then turn right

btfss PORTB,2 ;Check the right sensor
Change above line to PORTB,1
goto TurnLeft ;If the right sensor is on then turn left

I think that should get it working for you.
Jeff
 
Hi
Need to change:

Start movlw 0x03 ;turn on both motors
movwf PORTA ;do above

Change the above line to movwf PORTB
btfss PORTB,1 ;Check the left sensor
Change above line to PORTB,0
goto TurnRight ;If the left sensor is on then turn right

btfss PORTB,2 ;Check the right sensor
Change above line to PORTB,1
goto TurnLeft ;If the right sensor is on then turn left

I think that should get it working for you.
Jeff

hi Jeff,

The program dosn't/didn't work.?
 
Last edited:
hi Jeff,
Providing the OP moves the pin wiring for his sensors to pins PORTB.0 and .1 it will work, then you are correct.:)

I would still recommend the other changes I suggested.
 
Hi isOlated,
Are you just trying to turn on LEDS right now to see if it works?
Are you using any switches?
I agree with you Eric on the other changes also.
Jeff
 
Last edited:
Hi isOlated,
Are you just trying to turn on LEDS right now to see if it works?
Are you using any switches?
I agree with you Eric on the other changes also.
Jeff


Hi Jeff,
The OP has gone quiet. Dont know his location.?

The way he described the problem, the switches were connected to the PIC, but just one LED constantly flashed.
He was setting PORTB.0 and .1 set for inputs, but testing PORTB.2 and .1.
So PORTB.2 being an output was always low, the program read it as a switch press...
 
Thanks for all the help,
I live in Australia which is why I went quiet, sorry, I posted it late at night because I had another look over the code and still couldn't see anything wrong. I'm at school right now so I'll try all of the suggestions when I get back home.

Again, thanks for all the help I knew it would be something obvious.
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top