News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Button

Started by Brett, Jan 11, 2022, 11:34 AM

Previous topic - Next topic

Brett

Hi, I have got stuck trying to use the "Button", I have used it before in other projects with no problem, but now I cant get a response from it. I have checked the pin voltage with a meter to make sure its working- it is, and also tried other ports/bits and still cant get a response to the switch
here is my code, using the SSD1306 libraries (kindly supplied by users here, for which many thanks-its a really good alternative to LCD)
 

Device = 18F57Q43
Declare Xtal = 64
Config_Start
  FEXTOSC = OFF   ;EC (external clock) above 8 MHz
  RSTOSC = HFINTOSC_64MHZ   ;HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1
  CLKOUTEN = OFF   ;CLKOUT function is disabled
  PR1WAY = On   ;PRLOCKED bit can be cleared and set only once
  CSWEN = On   ;Writing to NOSC and NDIV is allowed
  FCMEN = On   ;Fail-Safe Clock Monitor enabled
  MCLRE = EXTMCLR   ;If LVP = 0, MCLR pin is MCLR; If LVP = 1, RE3 pin function is MCLR
  PWRTS = PWRT_OFF   ;PWRT is disabled
  MVECEN = On   ;Multi-vector enabled, Vector table used for interrupts
  IVT1WAY = On   ;IVTLOCKED bit can be cleared and set only once
  LPBOREN = OFF   ;Low-Power BOR disabled
  BOREN = SBORDIS   ;Brown-out Reset enabled , SBOREN bit is ignored
  BORV = VBOR_1P9   ;Brown-out Reset Voltage (VBOR) set to 1.9V
  ZCD = OFF   ;ZCD module is disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
  PPS1WAY = On   ;PPSLOCKED bit can be cleared and set only once; PPS registers remain locked after one clear/set cycle
  STVREN = On   ;Stack full/underflow will cause Reset
  LVP = On   ;Low voltage programming enabled. MCLR/VPP pin function is MCLR. MCLRE configuration bit is ignored
  XINST = OFF   ;Extended Instruction Set and Indexed Addressing Mode disabled
  WDTCPS = WDTCPS_31   ;Divider ratio 1:65536; software control of WDTPS
  WDTE = OFF   ;WDT enabled regardless of sleep; SWDTEN is ignored ================================================== changed by me
  WDTCWS = WDTCWS_7   ;window always open (100%); software control; keyed access not required
  WDTCCS = SC   ;Software Control
  BBSIZE = BBSIZE_512   ;Boot Block size is 512 words
  BBEN = OFF   ;Boot block disabled
  SAFEN = OFF   ;SAF disabled
  Debug = OFF   ;Background Debugger disabled
  WRTB = OFF   ;Boot Block not Write protected
  WRTC = OFF   ;Configuration registers not Write protected
  WRTD = OFF   ;Data EEPROM not Write protected
  WRTSAF = OFF   ;SAF not Write Protected
  WRTAPP = OFF   ;Application Block not write protected
  Cp = OFF   ;PFM and Data EEPROM code protection disabled
Config_End

$define SSD1306_Protocol_I2C
Include "SSD1306_Def_v1.11.inc"
Include "Graphic_Def_v1.01.inc"
Include "SSD1306_BB_Sub_v1.11.inc"
Include "Graphic_Sub_v1.01.inc"
Include "Consolas_12.inc"
SelectFont(Consolas_12)

Declare SDA_Pin PORTA.6
Declare SCL_Pin PORTA.7

Cls
DelayMS 100
Print At 1,1, "START OK   "
RefreshDisplay()
DelayMS 500
Cls

Dim R As Byte
Dim Cnt As Word

Symbol A PORTF.4
Input PORTF
PinPullup A

Cnt=0

loopy:

Button A,1,255,250,R,1,sub1     ' i tried changing the downstate to 0 as I think it should be in this case, but it just jumps to the label with no press

Print At 1,14, "COUNT=", Dec Cnt,"     "
RefreshDisplay()

GoTo loopy


sub1:
Print At 1,28, "inc"
RefreshDisplay()


Cnt = cnt+1
GoTo loopy





Can anyone see an obvious error, it has me stumped.
Thanks :)

 

Mapo

#1
.

John Lawton

I think there is a syntax error in your symbol definition which may be part of the problem. Should it not be:

Symbol A = PORTF.4

John


top204

I can see the problem and I am now on it. It has to do with the SFR positions on the newer Q devices. They are in low RAM, but some of the compiler's library routines that need a port's address is setting the FSR0H SFR as if it is in high RAM, as they used to be.

I'll have an update as soon as I can find the 18F27Q43 device I have, for tests.

Brett

Hi,
John - Thanks,  I have used that syntax for other programs without any problems, but looking at the manual you are right, I should have the syntax you suggest, but it didn't fix it when I tried.

Les - Thanks for that, I will use some alternative code for now to make this project work. I also had a problem using the I2Cout command which did not produce any output from the same device, but the Busout worked just fine, could that be a device specific issue also?

Thanks, Brett.

top204

Unfortunately, yes. The Port Address is the problem with the I2C commands as well with the new 18F Q devices. I looked in my log book, and I was supposed to make the changes before releasing the compiler version that supported them, but things must have gotten on top of me and I forgot to change the subtle things in these devices.

Sorry for that.

Brett


No worries Les, now I know its not something I was doing wrong I can work around it. Would it be fair to assume functions like Pulsein that reference a port.pin will be effected too ?
Thanks, Brett.

Brett

Everything working fine after the latest update :)

Thanks very much :)