PIC program #2: Binary Counter – FREE Preview!

We now build and program a binary counter to learn some new instructions such as Increment and Bit Test.

This is the code for the program:

list p=16F1455 ; list directive to define processor
#include “p16F1455.inc” ; processor specific variable definitions

__CONFIG _CONFIG1, _FOSC_ECL & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_ON & _FCMEN_OFF
__CONFIG _CONFIG2, _WRT_OFF & _CPUDIV_CLKDIV6 & _USBLSCLK_48MHz & _PLLMULT_3x & _PLLEN_ENABLED & _STVREN_ON & _BORV_LO & _LPBOR_OFF & _LVP_ON

errorlevel -302 , -207 ; suppress message 302 from list file

banksel TRISC
clrf TRISC
banksel LATC
clrf LATC
loopy1:
incf LATC
btfsc LATC, 4
clrf LATC
goto loopy1
end

 

Questions

  • 1

    flowduino

    binary_counter working.. See electronicwizard (youtube) or just David Lee on facebook.

    • Ian Juby

      Okay, interesting. I’ve really appreciated your sharing the challenges you meet along the way. An interesting thing that happened to me which is what I thought might have happened to you at first, is if I start up another project and don’t make it “Main project” then everytime you flash the chip, it’ll flash whatever program is currently set to “Main project”. I had to right-click on the program I was working on, and “set to main project”. Then it would flash the chip with that program. I don’t know why yours did what it did, it would be nice to know. Since that time I’ve made a point of making one of the steps in project set up to make sure the check box is checked to “Make as Main Project” (or whatever it says – very last screen in the project creation window).
      The PICKIT 3’s I provide in the kits are also the cheap Chinese knock-offs, and they work good, but have rather strange things going on with them too – like taking a ridiculously long time to get loaded on to the computer.
      Thanks for sharing!

  • 1

    Cynthia

    My counter is skipping numbers. It skips making a 3 for example. Any ideas?

    • Cynthia

      to make a more complete comment….. I think the counter is not skipping numbers, but the lights are not always lighting up so it looks as if it is skipping. It will make a 1, a 2, but not a three (no lights light up). It makes 4, 5, then only makes one light for 6, nothing for 7, 8 is good, then does not make 9, makes 10, but not 11, 12, 13. Could it be because we had to set our voltage at 3.5?

  • 3

    Cynthia

    from our group, 3 people had total success and two of us still have situations where the binary counter is not always lighting up the correct lights. We had done rebuilds of our projects and checked wiring. All lights are working at some point, so it is not a bad light. Do you have any other ideas about what we should check?

    • Ian Juby

      Can you post a picture of the circuit not working as well as the code used?

    • Cynthia

      Hi Ian. A movie is too big of a file to post (since the max is 8MB). I cut and pasted your code. You can tell that the program is moving through the numbers correctly, but not all the lights that are supposed to come on, come on. It never has more than 2 lights on at any time.

    • Cynthia

      So, for anyone reading this who has had similar troubles…. the problem was…. the blue LED. I was using two blue LED and two yellow LED and it wasn’t lighting up correctly. When I switched to using red, green and yellow… everything worked just fine.

  • 0

    Cynthia

    just an fyi… I had to use a voltage setting of 3.375 on a different computer in order to get the lights to increment correctly