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.

So...I have my junebug....and Im totally lost

Status
Not open for further replies.
blueroomelectronics said:
2. INTCON2.7 should be written as INTCON2.NOTRBPU (same thing better syntax)
Bill,
I looked for this in the 18F1320 include file and couldn't find it, infact, non of the bit fields are defined. I also just tried it and it doesn't work. Is there something I am missing?

AtomSoft,
Clearing INTCON2.7 turns on the weak pullup resistors on Port B.

Mike.
 
Pommie said:
Bill,
I looked for this in the 18F1320 include file and couldn't find it, in fact, none of the bit fields are defined. I also just tried it and it doesn't work. Is there something I am missing?
I've found quite a few errors like that in the Microchip include files. The 16F88 assembler include, in particular, is missing a lot of stuff and has many errors.

I just fix the include file, using the datasheet as a reference. Add whatever is needed and correct the errors. Simple enough. An incorrect include is pretty annoying.
 
Hi Futz,

I was talking about the Swordfish include file. This doesn't contain any bit variables whatsoever and I'm not sure how to declare them.

Mike.
 
Opps it's NOT_RBPU, I've use RBPU as it looks nicer IMO than NOT_RBPU
Code:
;----- INTCON2 Bits ----------------------------------------------------
NOT_RBPU        EQU  H'0007'
RBPU            EQU  H'0007'
INTEDG0         EQU  H'0006'
INTEDG1         EQU  H'0005'
INTEDG2         EQU  H'0004'
TMR0IP          EQU  H'0002'
T0IP            EQU  H'0002'
RBIP            EQU  H'0000'
From the 18F1320.inc file
 
It shows up under the processor (as soon as you enter one in your program) in Code Explorer when you use the Swordfish IDE (It's a really good IDE IMO)
Here's the 18F1320
Code:
{
****************************************************************
*  Name    : 18F1320                                           *
*  Author  : David John Barker                                 *
*  Notice  : Copyright (c) 2006 Mecanique                      *
*          : All Rights Reserved                               *
*  Date    : 17/11/2006                                        *
****************************************************************
}

module SystemTypes

// system header...
#const _core = $0012                   // processor core
#const _ram_banks = $01                // 1 RAM bank(s) used
#variable _maxaccess = $80             // access ram is 128 bytes
#variable _maxram = $0100              // 256 bytes of user RAM
#variable _maxrom = $002000            // 8 KB of program ROM
#const _eeprom = $0100                 // 256 bytes of EEPROM
#const _eeprom_start = $F00000         // EEPROM start address
#const _ports = $02                    // 2 available ports
#const _ccp = $00                      // CCP module NOT supported
#const _eccp = $01                     // 1 ECCP module(s) available
#const _mssp = $00                     // MSSP module NOT supported
#const _usart = $01                    // 1 USART(s) available
#const _adc = $07                      // 7 ADC channels available
#const _adres = $0A                    // 10 bit ADC resolution
#const _comparator = $00               // comparator module NOT supported
#const _psp = $00                      // Parallel Slave Port (PSP) is NOT supported
#const _can = $00                      // onboard CAN is NOT supported
#const _usb = $00                      // USB is NOT supported
#const _ethernet = $00                 // onboard Ethernet is NOT supported
#const _flash_write = $01              // FLASH has write capability

// special function registers...
public system
   TOSU as byte absolute $0FFF,
   TOSH as byte absolute $0FFE,
   TOSL as byte absolute $0FFD,
   STKPTR as byte absolute $0FFC,
   PCLATU as byte absolute $0FFB,
   PCLATH as byte absolute $0FFA,
   PCL as byte absolute $0FF9,
   TBLPTRU as byte absolute $0FF8,
   TBLPTRH as byte absolute $0FF7,
   TBLPTRL as byte absolute $0FF6,
   TABLAT as byte absolute $0FF5,
   PRODH as byte absolute $0FF4,
   PRODL as byte absolute $0FF3,
   INTCON as byte absolute $0FF2,
   INTCON2 as byte absolute $0FF1,
   INTCON3 as byte absolute $0FF0,
   INDF0 as byte absolute $0FEF,
   POSTINC0 as byte absolute $0FEE,
   POSTDEC0 as byte absolute $0FED,
   PREINC0 as byte absolute $0FEC,
   PLUSW0 as byte absolute $0FEB,
   FSR0H as byte absolute $0FEA,
   FSR0L as byte absolute $0FE9,
   WREG as byte absolute $0FE8,
   INDF1 as byte absolute $0FE7,
   POSTINC1 as byte absolute $0FE6,
   POSTDEC1 as byte absolute $0FE5,
   PREINC1 as byte absolute $0FE4,
   PLUSW1 as byte absolute $0FE3,
   FSR1H as byte absolute $0FE2,
   FSR1L as byte absolute $0FE1,
   BSR as byte absolute $0FE0,
   INDF2 as byte absolute $0FDF,
   POSTINC2 as byte absolute $0FDE,
   POSTDEC2 as byte absolute $0FDD,
   PREINC2 as byte absolute $0FDC,
   PLUSW2 as byte absolute $0FDB,
   FSR2H as byte absolute $0FDA,
   FSR2L as byte absolute $0FD9,
   STATUS as byte absolute $0FD8,
   TMR0H as byte absolute $0FD7,
   TMR0L as byte absolute $0FD6,
   T0CON as byte absolute $0FD5,
   OSCCON as byte absolute $0FD3,
   LVDCON as byte absolute $0FD2,
   WDTCON as byte absolute $0FD1,
   RCON as byte absolute $0FD0,
   TMR1H as byte absolute $0FCF,
   TMR1L as byte absolute $0FCE,
   T1CON as byte absolute $0FCD,
   TMR2 as byte absolute $0FCC,
   PR2 as byte absolute $0FCB,
   T2CON as byte absolute $0FCA,
   ADRESH as byte absolute $0FC4,
   ADRESL as byte absolute $0FC3,
   ADCON0 as byte absolute $0FC2,
   ADCON1 as byte absolute $0FC1,
   ADCON2 as byte absolute $0FC0,
   CCPR1H as byte absolute $0FBF,
   CCPR1L as byte absolute $0FBE,
   CCP1CON as byte absolute $0FBD,
   PWM1CON as byte absolute $0FB7,
   ECCPAS as byte absolute $0FB6,
   TMR3H as byte absolute $0FB3,
   TMR3L as byte absolute $0FB2,
   T3CON as byte absolute $0FB1,
   SPBRGH as byte absolute $0FB0,
   SPBRG as byte absolute $0FAF,
   RCREG as byte absolute $0FAE,
   TXREG as byte absolute $0FAD,
   TXSTA as byte absolute $0FAC,
   RCSTA as byte absolute $0FAB,
   BAUDCTL as byte absolute $0FAA,
   EEADR as byte absolute $0FA9,
   EEDATA as byte absolute $0FA8,
   EECON2 as byte absolute $0FA7,
   EECON1 as byte absolute $0FA6,
   IPR2 as byte absolute $0FA2,
   PIR2 as byte absolute $0FA1,
   PIE2 as byte absolute $0FA0,
   IPR1 as byte absolute $0F9F,
   PIR1 as byte absolute $0F9E,
   PIE1 as byte absolute $0F9D,
   OSCTUNE as byte absolute $0F9B,
   TRISB as byte absolute $0F93,
   TRISA as byte absolute $0F92,
   LATB as byte absolute $0F8A,
   LATA as byte absolute $0F89

// system ports...
public system port
   PORTB as byte absolute $0F81,
   PORTA as byte absolute $0F80

// alias...
public dim
   FSR0 as FSR0L.AsWord,
   FSR1 as FSR1L.AsWord,
   FSR2 as FSR2L.AsWord,
   TABLEPTR as TBLPTRL.AsWord

// configuration fuses...
public config
   OSC(OSC) = [LP, XT, HS, EC, ECIO, HSPLL, RCIO, INTIO2, INTIO1, RC],
   FSCM(FSCM) = [OFF, ON],
   IESO(IESO) = [OFF, ON],
   PWRT(PWRT) = [ON, OFF],
   BOR(BOR) = [OFF, ON],
   BORV(BORV) = [45, 42, 27],
   WDT(WDT) = [OFF, ON],
   WDTPS(WDTPS) = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768],
   MCLRE(MCLRE) = [OFF, ON],
   STVR(STVR) = [OFF, ON],
   LVP(LVP) = [OFF, ON],
   DEBUG(DEBUG) = [ON, OFF],
   CP0(CP0) = [ON, OFF],
   CP1(CP1) = [ON, OFF],
   CPB(CPB) = [ON, OFF],
   CPD(CPD) = [ON, OFF],
   WRT0(WRT0) = [ON, OFF],
   WRT1(WRT1) = [ON, OFF],
   WRTB(WRTB) = [ON, OFF],
   WRTC(WRTC) = [ON, OFF],
   WRTD(WRTD) = [ON, OFF],
   EBTR0(EBTR0) = [ON, OFF],
   EBTR1(EBTR1) = [ON, OFF],
   EBTRB(EBTRB) = [ON, OFF]

// default fuses...
config
   OSC = HS,
   IESO = OFF,
   PWRT = ON,
   BOR = ON,
   BORV = 27,
   WDT = OFF,
   WDTPS = 128,
   STVR = ON,
   LVP = OFF,
   DEBUG = OFF
 
I looked in the include file when I originally wrote the code so I could use the correct label. My problem is that RBPU does not appear anywhere in that file and so Swordfish complains that it isn't defined.

Mike.
 
From the Data Sheet: (PG 89)
Code:
The TRISA register controls the direction of the RA
pins

The operation of pins RA3:RA0 as A/D converter
inputs is selected by clearing/setting the control bits in
the ADCON1 register (A/D Control Register 1).

• TRIS register (data direction register)
• PORT register (reads the levels on the pins of the
device)
• LAT register (output latch)
So
1. TRISA = %11111101 // would set all pins/bits on Tris A to input except pin/bit 6

2. if (PORTA.7=0) then // would be used to check a port for its current level (high/low)

3. LATA.7 = 1 // would set the bit/pin to a 1 (high) alternative HIGH(LATA.7)

4. ADCON1 = %11111111 // Would set all pins on PORTA to digital input (then you can use TRISA to set certain pins to input/output)


Would that be right so far?
 
Last edited:
AtomSoft said:
From the Data Sheet:(PG 89)
Code:
The TRISA register controls the direction of the RA
pins

The operation of pins RA3:RA0 as A/D converter
inputs is selected by clearing/setting the control bits in
the ADCON1 register (A/D Control Register 1).

• TRIS register (data direction register)
• PORT register (reads the levels on the pins of the
device)
• LAT register (output latch)
So
1. TRISA = %11111101 // would set all pins/bits on Tris A to input except pin/bit 6
Nearly, the bits are the other way around so it should be TRISA=%10111111.
2. if (PORTA.7=0) then // would be used to check a port for its curret level (high/low)
Yes, but only if the pin is a digital input. Analogue inputs always read zero.
3. LATA.7 = 1 // would set the bit/pin to a 1 (high) alternative HIGH(LATA.7)
LATA.7 = 1 would set the bit/pin to a 1 (high) if TRISA.7 = 0 (output).
HIGH(LATA.7) sets the TRIS and LAT bits and so would work.

You should also set ACDON1=$7f in order to configure the pins as digital and not analogue.

Mike.
 
Ok i just notice backward TRISA lol so its 7:0 right.
Ok so HIGH/LOW is a built in command that sets both TRIS and LAT.

ADCON1 (made a update before your post)

So would be like :

Code:
1. TRISA = %10111111 // would set all pins/bits on Tris A to input 
except pin/bit 6 It reads from 7-0 (check data sheet)

2. if (PORTA.7=0) then // would be used to check a port for its current 
level (high/low) but only if the pin is a digital input. Analogue 
inputs always read zero.

3. LATA.7 = 1 would set the bit/pin to a 1 (high) if TRISA.7 = 0 
(output). HIGH(LATA.7) sets the TRIS and LAT bits and so would work.

4. ADCON1 = $7f  // hex for %11111111 // Would set all pins on PORTA to digital input

Gonna make a like cheat sheet or Notes to keep handy in case i forget stuff.

Now knowing this info i think i better understand the ASM i read in the past.
 
Last edited:
> I looked in the include file when I originally wrote the code so I
> could use the correct label. My problem is that RBPU does not appear
> anywhere in that file and so Swordfish complains that it isn't defined.

Swordfish only defines the registers in the system file, not the bitnames. However, you can do this quite easily in your program. For example,

Code:
Dim NOT_RBPU As INTCON2.7
NOT_RBPU = 1

With a little effort, you can also create structures similar to the ones used by Microchips C compiler. For example,

Code:
Structure TINTCON2
   _byte As Byte
   NOT_RBPU As _byte.7
   RBPU As _byte.7
   INTEDG0 As _byte.6
   INTEDG1 As _byte.5
   INTEDG2 As _byte.4
   TMR0IP As _byte.2
   RBIP As _byte.0
End Structure
Public Dim INTCON2 As TINTCON2 Absolute $0FF1 // get address from system file

Then you can access like this

Code:
INTCON2.RBPU = 1
INTCON2._byte = $FF

Remember though that when defining a 'structured' register name, the compiler will treat INTCON2 as a structure. This can cause problems when comparing or assigning byte values. In those instances, you need to access the 'byte' part. For example,

Code:
if INTCON2._byte = $FF then...
 
Last edited:
in my 18F1320.inc file i see:
; INTCON2
NOT_RBPU = 7
RBPU = 7
INTEDG0 = 6
INTEDG1 = 5
INTEDG2 = 4
TMR0IP = 2
T0IP = 2
RBIP = 0

Ok back to the programming :

These ports have to be digital because they are always closed(on) right? So instead of measuring a on.off you compare voltages or something.

So if i was using a switch to control some LEDs and a relay i would make it analog? Or maybe just leave it digital anyway and add a pull-down resistor to it. So when switch S1 is closed (on), it has a direct connection to VCC, which takes it to the high state. and when switch S1 is open(off) it has a direct connection to ground, which takes it to the low state.

does that sound right?
 
Welcome to the forums Mr Barker, it's nice to see you found us.
Just wanted to say Swordfish is an incredible product, nice work.

PORTB has built in pullups (something like a 47K resistor) so all you need is a switch to the pin and GND. Analog is only for analog, but it IS possible to make an analog keypad (popular among the pin frugal) see the Tips & Tricks pdf below.

Microchip has tons of app notes on their site, tips & tricks too.
And the excellent tutorials from
Nigel Goodwin ,
David Meiklejohn , Gooligum electronics

And for Swordfish their **broken link removed** have plenty of examples and the built-in Swordfish BASIC help menu has many examples too.

Gotta run and get Coffee (Tim Hortons) now :)
 

Attachments

  • PIC Tips n Tricks Hardware Techniques.pdf
    488.5 KB · Views: 208
AtomSoft said:
There we go a nice PDF thanks a bunch!

I would rather use ADC then Capacitor charge time

For sure, the HW A/D is a very popular PIC option. The app notes were often written with the most basic PICs in mind.
 
POMMIE :

Whats this do? (really WPUs mean?)

INTCON2.7=0 //WPUs on port B

Has to do with pull up?

0 = PORTB pull-ups are enabled by individual port latch values

I think i know why i had so many issues in the past. Usually when i read a data sheet i never really read it entirely i just skim through it. I see a lot of info now. Like the above and below

Page 158:
Code:
REGISTER 17-2: ADCON1: A/D CONTROL REGISTER 1

bit 7 Unimplemented: Read as ‘0’

bit 6 PCFG6: A/D Port Configuration bit – AN6
   1 = Pin configured as a digital port
   0 = Pin configured as an analog channel – digital input disabled and reads ‘0’

bit 5 PCFG5: A/D Port Configuration bit – AN5
   1 = Pin configured as a digital port
   0 = Pin configured as an analog channel – digital input disabled and reads ‘0’

etc....

The issue is reading on a CRT monitor bothers after a while. I need a LCD lol Um.. Also i need a new printer (possibly a laser b/w).

When you purchase a chip online(microchip.com) does it come with printed Data Sheet and stuff?
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top