hopefully simple code


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2005
    Posts
    9

    Question hopefully simple code

    i'm relatively new to programing using picbasic. i want to program a 16f84 to count to 0 to 255 in binary with a pushbutton to advance count one step for each press of the button.
    help greatly appreciated.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Counting is counting, whether it's Binary, Decimal, Hexadecimal or in Latin. It's how you finally OUTPUT it that counts. Here is a simple program that will count (add one) each time your Button is pressed, and output the status in BINARY to an array of LEDs.

    Consider the following Program and circuit.

    You have a PushButton connected between PortA.0 and Vss. A pull-up Resistor (say 10K) is connected between PortA.0 and Vdd. That means the pin is usually High (Logic 1) when NOT pressed, and goes Low (Logic Zero) when pressed.

    PortB has an LED on each pin connected between the pin and Vss via a Resistor (one for each LED), lets say 330R.

    The program variable CounterA is incremented once each time the PushButton is pressed, it's status is then sent to PortB so you can see it happen. The Pause is there to debounce the Pushbutton from giving you multiple counts on one press. The While-Wend pair is there to ensure you lift your finger off the button before a new count is registered. The rest you can figure yourself between the PICBasic manual and the Datasheet.

    Code:
    	'
    	'	Program Hardware Defines
    	'	------------------------
    	PushButton var PortA.0
    	LEDArray var PortB
    
    	'
    	'	Program software Defines
    	'	------------------------
    	CounterA var Byte
    
    	'
    	'	Initialise Program
    	'	------------------
    	TRISA=%11111111
    	TRISB=%00000000
    	CounterA=0
    
    	'
    	'	Main Program Loop
    	'	-----------------
    Loop:
    	If PushButton=0 then
    		CounterA=CounterA+1
    		LEDArray=CounterA
    		Pause 10
    		While Pushbutton=0:Wend
    		endif
    	Goto Loop
    
    	end

  3. #3
    Join Date
    Sep 2005
    Posts
    9


    Did you find this post helpful? Yes | No

    Wink many thanks

    the program you sent me work perfect.
    greatly appreciated.
    hope to become a lot smarter visiting your forum.
    thanks again for an extremely quick response and for thinking about us "newbies"
    dominic

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Be confident Dominic. I get a big part of my knowledge here by trying to help other with their specific problem.

    Have fun and good luck!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Nokia COLOR LCD PicBasicPro 2.50a example code
    By skimask in forum Code Examples
    Replies: 49
    Last Post: - 28th September 2011, 01:43
  2. what's wrong 16F877A simple code?
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 30th October 2009, 01:11
  3. Manchester coding/decoding Code help
    By financecatalyst in forum Code Examples
    Replies: 0
    Last Post: - 25th August 2009, 19:05
  4. Simple Wireless Communication
    By jhorsburgh in forum General
    Replies: 6
    Last Post: - 27th March 2008, 11:02
  5. PIC18F4525 & LCD simple code problem
    By aggie007 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd November 2007, 16:29

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts