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.

Multiplex switches

Status
Not open for further replies.
While im waiting for a reply on the above take a look at this. Does it make sense? I was trying to integrate the ICSP with a breadboard. What cha think?

**broken link removed**

Basically you jump from the board to the breadboard then jump the pins of the chip to the locations above. I might just make it like a a plug and play thing So you put chip on board and all is already connected to breadboard.
 
Last edited:
AtomSoft said:
While im waiting for a reply on the above take a look at this. Does it make sense? I was trying to integrate the ICSP with a breadboard. What cha think?

Basically you jump from the board to the breadboard then jump the pins of the chip to the locations above. I might just make it like a a plug and play thing So you put chip on board and all is already connected to breadboard.
Have a look at this thread for some pics of how it's done.

"Plug and play" will only work if you only use certain PICs. Different models have MCLR, PGD and PGC in different places.

VPP goes to the MCLR pin. This connection also gets a 33K or so pullup resistor to VDD.

5V and Ground go to the power rails.

PGD and PGC go to the PGD and PGC pins on the MCU.

Very simple.

To make the breadboard socket I took a 2x5 ICD socket and soldered it directly to a 2x5 piece of two row header.
 
Last edited:
Thanks for the info. I actually was just bored and needed something to do lol I am not going to make that breadboard stuff was just looking into it while i wait for anyone who can confirm that this is ok:

**broken link removed**
 
Also is a macro like a Function ? Like in VB6 you would:
Code:
public function SayHi (TheName as string)
      msgbox "Hi " & TheName & "!"
end function

So for junebug it would be like

Code:
LED macro x,y ; MACRO LED <PORTA>, <TRISA>

Public function LED(x, y) as long
      LATA = x
      TRISA = y
      
      Delay();
End function

and to call it would be like

Code:
LED1 = LED ("00000001", "10111110")

Would that be a good comparison to ?

Code:
LED macro x,y ; MACRO LED <PORTA>, <TRISA>
      movlw x
      movwf LATA       ; LATA = x
      movlw y
      movwf TRISA      ; TRISA = y
      call Delay           ; call the Delay subroutine
      endm                 ; end macro
and
Code:
LED1 LED b'00000001', b'10111110'
 
Last edited:
I stated posting this this AM but did not submit it.

The most common way to hook up the ICSP is to put a male pinheader on the target board. Use a ribbon cable with female IDC connectors on both ends. Like in the picture of the Junebug with a Mongoose.
 
I did change it back to Male Header on the schematic. I was just asking if the above schematic seems ok. Like if i wire that way would i be able to program it and also use it.
 
What is the purpose of R4 the 22K resistor between RA0 and VDD? RA0 in one of the three charlieplex lines.

When drawing a schematic do not run the lines inside the PIC and through the text. It makes it hard to look at. It is OK, even common, to have lines cross in a schematic. They only connect where there is a dot at the intersection.

Do not think of a macro as a function. A function is a single bit of code that you call with parameter substitution (goto and return from).

A macro is a pattern that can be used with substitution. The pattern is expanded inline. So if you use the macro six times you will have six copies of the macro code. A macro definition does not generate any code. Each time you use the macro code is generated.

NOTE: Compilers have the option of using a new copy of a function for each call. This is called an inline function. But for reasons of sanity I choose to ignore it here.
 
Ok i think i have a somewhat clear outlook on marcos now so it actually copies the code everytime its called?

so for every "LED1 LED b'00000001', b'10111110' ; LED <PORTA>, <TRISA>" there is a :
Code:
LED macro x,y ; MACRO LED <PORTA>, <TRISA>
movlw x
movwf LATA ; LATA = x
movlw y
movwf TRISA ; TRISA = y
call Delay ; call the Delay subroutine
endm ; end macro
Count equ 0 ; delay loop counter
org 0 ; reset vector
bsf ADCON1, 0 ; make RA0 digital

Hows this:
**broken link removed**
 
Regarding assembler macros. It is time to fire up MPLAB write some code with macros and assemble it. Look at the listing to see what is done each time you use a macro. You do not need me check it for you... you have the tools.

Schematic looks better, could work as is.

You might want to add a connector for power unless you always intend to power it via the ICSP connector.

Swap C1 end for end so that the curved (earth/gnd) part of the device connects to VSS. It is not a polarized cap so it would work either way but it is better to correct it just the same.
 
Code:
  0002    0E01     MOVLW 0x1                      17:    LED1	LED b'00000001', b'10111110'    ; LED <PORTA>, <TRISA>
  0004    6E89     MOVWF 0xf89, ACCESS
  0006    0EBE     MOVLW 0xbe
  0008    6E92     MOVWF 0xf92, ACCESS
  000A    EC27     CALL 0x4e, 0
  000E    0E40     MOVLW 0x40                     18:    LED2 	LED b'01000000', b'10111110'    ; LED <PORTA>, <TRISA>
  0010    6E89     MOVWF 0xf89, ACCESS
  0012    0EBE     MOVLW 0xbe
  0014    6E92     MOVWF 0xf92, ACCESS
  0016    EC27     CALL 0x4e, 0

So it actually recreated the code for each time LED was called. Does this waste more memory based on how many times you use it?

So its sort of like a function but instead of having that one block of code to run anything it copys the block to the address where the call to it was made and adds the information from the call into the copy of itself.

Sounds about right?

I also notice it called 0x4e which is 004E in the code which in turn is the DELAY address. Pretty cool stuff. Thanks for the info .

Just noticed something im going to try and make a macro brb 2 min
 
How would i go about setting 1 pin ? Like

TRISA BIT 2 to ouput?

I know how to set them all like 00111101 thats sets every pin tho.

Like can i specify which pin i want to set like a TRISA.7 = 0 or something

how would i do that in ASM or do i always have to set the others as well?

is it BCF and BSF?
like
BCF TRISA,7,0
 
Last edited:
So would this be how the HIGH(LED#) would work?

Code:
HIGHA  macro x 		    ; MACRO HIGHA <PORTA BIT>
	BCF TRISA,x,0       ; Clear the TRISA.X to make it output
        BSF LATA,x,0	    ; Set LATA.X to High
	endm 		       ; end macro

or

Code:
HIGHA  macro x 		    ; MACRO HIGHA <PORTA BIT>
	BCF TRISA,x,0       ; Clear the TRISA.X to make it output
        ;BTG PORTA x	    ; Toggle PortA.X or should i use 
        BSF LATA,x,0         ; BIT SET LATA.X 
	endm 		       ; end macro

Used like:
HIGHA 3 ; This sets bit 3 on trisa to output and sets it high.

These seem like some nice commands i barely see in use:

CPFSEQ
CPFSGT
CPFSLT
MOVF
MOVFF
MOVWF
 
Last edited:
Look at TRISA and PORTA in the SFR (Special Function Registers) window and you can see the bits changing as you step through the code.

Macros do not replace functions. Functions do not replace macros.

A macro is mostly just a shorthand (shortcut) way of generating code. Each time you use a macro it generates code based on the macro definition. But it does not generate any more code then if you had written the same code without the macro. It saves you time and keystrokes. Makes the code more readable if done correctly.

A function is code you call. In general there is only one copy of it. It saves program memory but there is overhead in setting up the parameter passing.

For shorter "things" a macro is more efficent.

You can learn more by running code in the simulator then I could teach you on the forum. I am not fluent in C18 assembler and do not care to be. Paid my dues a long time ago.
 
Got this to work pretty cool. I seen it in SwordFish i think. Thought id make it in ASM
Code:
 		list p=18F1320
   		include <p18F1320.inc>
		CONFIG OSC = INTIO2, WDT = OFF, LVP = OFF

HIGHA  macro x 		    ; MACRO HIGHA <PORTA BIT>
       BCF TRISA,x       ; Clear the TRISA.X to make it output
       BSF LATA,x         ; BIT SET LATA.X 
       call Delay
       endm 		       ; end macro
LOWA  macro x 		    ; OPPOSITE OF : MACRO HIGHA <PORTA BIT>
       BCF TRISA,x        ; Clear the TRISA bit
       BCF LATA,x	   'Clear the LATA bit
       call Delay
       endm 		       ; end macro
       Count equ 0 
	   org 0
Start 
	   movlw     b'01111111'  ;This is just to see what changed in SFR (7 has to be 0  in LATA )
	   movwf LATA              ;set it the same
	   movwf TRISA             ;set it the same
	   HIGHA 2
	   LOWA 2
       goto Start
Delay 
	decfsz Count, f 				; decrement Count and skip when zero
		goto $-2 						; not zero? repeat
		return 							; return
		END
 
Last edited:
Here's a way to multiplex 10 switches. I got the idea from blueroomelectronics' website, except he uses it for LEDs, so I thought, why not do it with siwtches?

If you worried about the diodes, you can get SMT packages that contain two in a package.

This will only use three I/O pins for 10 switches or just two if you don't use the reset pin.
 

Attachments

  • Multiplex switches.GIF
    Multiplex switches.GIF
    3 KB · Views: 649
That's the method I use on the Dragonfly. Of course a PIC with more pins is often better / cheaper than adding glue logic.
I used the 4017 to make it impossible to run more than one display / switch at once. Another popular demux is the 74LS138
 
wow nice im looking at Data Sheet for 4017 right now. The 74LS138 looks a bit confusing to me lol. Maybe because i just went over quickly will be sure to check out both.

Tell me what you think of this idea:

I dont own a laser printer so i hand draw my schematics onto a PCB But i seem to miss the chip sizes. Like i drill wrong. But i bought a Pre Made Radio Shack board and just marked it so i can drive perfect(close to it) holes and fit a chip nicely here are some pics:

**broken link removed**

and

**broken link removed**

The other holes not in the corner with the black lines where hand done and none are good. So i would suggest PCB Pref board if hand drawn or even if printed just to get perfect or close to perfect holes.(without as much movement)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top