arrays LEDs Switches


Closed Thread
Results 1 to 3 of 3
  1. #1
    ilteris's Avatar
    ilteris Guest

    Default arrays LEDs Switches

    Hello Folks,

    I am trying to control these tiny LEDs with my switches, right now 8 for 8 but it is going to be 25 for 25 in the end so this is just a proto to figure out whats going on. MY code is working in a sense, I just happen to get high all of my LEDs like I wanted and made some low according to me, but when I try to connect them to my switches which are lying on the PORTB, I just could control the PINO of the PORTB, I am pasting my code below, and looking for your answers.

    Thanks in advance
    ilteris.

    Code:
       define OSC 4
       
       start:
       TRISC = 0
       TRISB = 1
       PORTC = 255
       PORTB = 255
       i var BYTE 
       j var BYTE
       myByte var BYTE
       delayTime var Byte
       mySwitch var  byte
       delayTime = 100
       pause delayTime
           
       main:
      
      for j=0 to 7 
      if PORTB.0(j) = 1 then
           mybyte.0(j) = 0
             PORTC = myByte
      
       else
    
       mybyte.0(j) = 1
          PORTC = myByte
      endif
            next
            
            
         for i=0 to 7 
            if i = 4 then
       myByte.0(i) = 0
              PORTC = myByte
       else
       
       myByte.0(i) = 1
       PORTC = myByte
         endif
       next   
       goto main

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


    Did you find this post helpful? Yes | No

    Default

    You are only setting Bit 0 of PortB to input... Try this...

    Code:
    	TRISB=%11111111
    	TRISC=%00000000
    	Option_Reg.7=0
    
    	Mybyte var Byte
    
    Loop:
    	MyByte=PortB
    	PortC=Mybyte
    	Pause 100
    	Goto Loop
    
    	End

  3. #3
    ilteris's Avatar
    ilteris Guest


    Did you find this post helpful? Yes | No

    Default

    hello Melanie,

    Thanks for the quick feedback although I am not sure I understood it correctly, I try adding this snippet to my with no dice, also open a new file and tried in that too but it is still no go, can you elaborate it quite a bit, also I couldnt find any documents on option_reg, can you tell me what is it?

    Thank you so much for your patience.
    ilteris.

Similar Threads

  1. Run a string of LEDs from the mains
    By The Master in forum Off Topic
    Replies: 30
    Last Post: - 1st October 2009, 18:55
  2. Using LEDs as light sensors
    By skimask in forum Code Examples
    Replies: 3
    Last Post: - 30th December 2006, 22:19
  3. switches & LEDs ... my first attempt
    By yankee in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 28th January 2006, 12:51
  4. controlling leds with the switches
    By ilteris in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th October 2005, 21:02
  5. Replies: 5
    Last Post: - 16th February 2005, 11:57

Members who have read this thread : 0

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