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.
AtomSoft said:
ADCON1 only is used for setting analog or digital.
Yes ADCON1 configures the PINS. Prior to doing a conversion you need to select which pin you are going to sample. That is the functon of ADCON0: CHS2:CHS0:

I think i would then use TRISA = 10111111 to make Bit 5:0 input 7:6 is for clock right? Thats another issue for later on.
You need to look at both the fuse configuration and the oscilator control registers.

So TRISA = BF or 10111111 binary // set i/o pins to in for A
So TRISB = 00 or 00000000 binary // set i/o pins to out for B

Ok thanks

Most people just blink an LED the first time out :) Start with that then try to read you switches.
 
Debouncing buttons can be fun, vertical counters too.
3V0 here's something I think would work well in C18, a bounce counter.
Press a button, count the bounces for 500ms, display result on the serial port.
 
lol Sort of. Ok ill ask better

1. what is the oscillator on a Junebug?
2. Not using the junebug can i use 555 timer as a OSC for the 1320?
3. If not #2 then i would have to use a resistor capacitor or ?

I would blink a led from the junebug but its like its already setup. I would want to make my own at least use a breadboard to assemble just the chip and core components. I will draw a small schem in 1 min. I want you to tell me if my schem would be compatible with the junebug code

Code:
; *** Junebug 18F1320 LED sequencer demo ***
; Flashes LEDs1 thru 6 from left to right forever
; DIP Switch (SW6) must have TUTOR on (SW6-1,2,3) all other switches off
      list p=18F1320
      include <p18F1320.inc>
      CONFIG OSC = INTIO2, WDT = OFF, LVP = OFF
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
LED1 LED b'00000001', b'10111110'          ; LED <PORTA>, <TRISA>
LED2 LED b'01000000', b'10111110'          ; LED <PORTA>, <TRISA>
LED3 LED b'01000000', b'00111111'          ; LED <PORTA>, <TRISA>
LED4 LED b'10000000', b'00111111'          ; LED <PORTA>, <TRISA>
LED5 LED b'10000000', b'01111110'          ; LED <PORTA>, <TRISA>
LED6 LED b'00000001', b'01111110'          ; LED <PORTA>, <TRISA>
      goto LED1 ; loop forever
      Delay decfsz Count, f                      ; decrement Count and skip when zero
      goto $-2                                        ; not zero? repeat
      return                                           ; return
      END
 
Last edited:
You're going to love that the 18F1320 and most new PICs have a built in 1% oscillator, the 18F1320 can go from 31.25KHz to 8MHz (8 speeds) just programming OSCCON. No external parts required.
That said it can really go very fast with an external 10MHz crystal, it can be PLL (4x) to 40MHz internal (/4 so 10MHz instruction clock. 10MIPs)

This config fuse tells it to use it's internal osc and allow the oscillator pins to work as normal I/O
Code:
 CONFIG OSC = INTIO2
And this sets the speed
Code:
  movlf 0x72
  movwf OSCCON
Where the speed is 7=8MHz, 6=4MHz, 5=2MHz, 4=1MHz, 3=500KHz, 2=250KHz, 1=125KHz, 0=31.25KHz
the 2 simply sets the mode as internal.
 
Last edited:
The schematic for several PICs can be found in the Hello World Poster in the download section on my site.
I should make a Junebug specific version of that poster...
The 18F1320 would connect very much like the 16F628A
**broken link removed**
 
blueroomelectronics said:
Debouncing buttons can be fun, vertical counters too.
3V0 here's something I think would work well in C18, a bounce counter.
Press a button, count the bounces for 500ms, display result on the serial port.
That is a lot to do in one demo. Maybe build up to it adding a fuction at at time.
 
What is VPP PGD PGC? I see they go all the way to the other Pic . How would i implement this onto my board like if i wanted to make a led flasher only. Like a custom PCB with the 6 LEDs and the 3 resistors and the multiplexed layout.

I get confused because 1 pin has like 3-4 meanings. And it gets fustrating.
 
blueroomelectronics said:
You're going to love that the 18F1320 and most new PICs have a built in 1% oscillator, the 18F1320 can go from 31.25KHz to 8MHz (8 speeds) just programming OSCCON. No external parts required.
That said it can really go very fast with an external 10MHz crystal, it can be PLL (4x) to 40MHz internal (/4 so 10MHz instruction clock. 10MIPs)

This config fuse tells it to use it's internal osc and allow the oscillator pins to work as normal I/O
Code:
 CONFIG OSC = INTIO2
And this sets the speed
Code:
  movlf 0x72
  movwf OSCCON
Where the speed is 7=8MHz, 6=4MHz, 5=2MHz, 4=1MHz, 3=500KHz, 2=250KHz, 1=125KHz, 0=31.25KHz
the 2 simply sets the mode as internal.

THANK YOU this is makes me more happy lol
movlf 0x42 // 1MHz then ok cool
movwf OSCCON
 
I did just post the Ready Steady GO reaction timer code in another thread, similar but instead of counting time it would count bounces.

I do like the idea of building it up a function at a time. I plan on putting time aside for the book.
 
AtomSoft said:
Ok so what would i connect to MCLR if i was to make my own LED Flasher or my 4 Button thingy

MCLR PGC and PGD are used by ICSP/ICD to program and debug the processor. You need to add a ICSP connector to your board. I like to use the 2x5 IDC type connector like Bill uses on the Inchworm and Junebug.
 
oh ok . But do i really need to? What if my project doesnt have consist of a 2x5 on the board. Like i want to control 3 relays with 4 buttons

button1 = relay 1
button2 = relay 2
button3 = relay 3

button4 = relay 1,2 and 3 on
 
The small 18F1320 has 15.5 I/O pins available, the ICD takes 2.5 (PGC,PGD,MCLR) leaving 13 I/O for your buttons and relays. That's enough for 4 pushbuttons and 4 relays.
That said you CAN hook all 4 button the interrupt on change pins (RB4,5,6,7) as this does not violate the loading rule for the ICD. BUT you cannot use buttons 6 & 7 when the debugger mode is used (they will show as zero in that mode).

You could also program the PIC externally (See Firefly) in a ZIF socket. The 2x5 is simply a handy and robust connector style.
 
Last edited:
If you want to use one IO pin per button why did we did we bother doing the analog setup where you can put several on one pin? OK maybe just a fun ting to do...

If you are new to embedded programming you will want to use an ICSP connector so that you can do in circuit debugging.
 
MCLR PGC and PGD are used by ICSP/ICD to program and debug the processor.
OK i understand that but when done programming and all is well then i dont need anything connected to it afterwords right? Thats what i mean.

I will use the junebug to program the chip and debug it but then when done i want to remove the 18F1320 to place it on a PCB for individual use. Like my own gadget.

what i was asking is when im done with programming and the debug of it i dont have to have those 3 connected to anything anymore right.
 
Also i wanted to use 1 pin because it should be the thing to do. What if i want to make a upgrade in the future. Now i would have more pins available and dont need to change code. Only need to add code. Right?
 
AtomSoft said:
MCLR PGC and PGD are used by ICSP/ICD to program and debug the processor.
OK i understand that but when done programming and all is well then i dont need anything connected to it afterwords right? Thats what i mean.

I will use the junebug to program the chip and debug it but then when done i want to remove the 18F1320 to place it on a PCB for individual use. Like my own gadget.

what i was asking is when im done with programming and the debug of it i dont have to have those 3 connected to anything anymore right.
Yes. You can program the chip using the programmer (not debugger) and it will run without the 3 lines. You may or may not want to keep the MCLR line for use as a reset button.

When you start running short on pins it is easy and cheap enough to switch to a 28 or 40 pin chip. Not saying you have too.
 
so would this be the same as a bare parts needed to run the junebug code and program it?
Would i still need the 20Mhz thing even if set to CONFIG OSC = INTIO2
**broken link removed**
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top