Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:50 02 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Micromite 4.5E help

Author Message
goc30

Guru

Joined: 12/04/2017
Location: France
Posts: 435
Posted: 03:50pm 19 Mar 2019
Copy link to clipboard 
Print this post

hi

I want to use an expander chip MCP23017 to control some buttons and leds
for that i have to use an small pic32mx250
and micromite v4.5E

to verify all I put on Diy this 2 chips and make a little prog

'test mcp23017
'TRON
Dim vport As integer
Dim vport1 As integer
Dim vport2 As integer
Dim txport As string
SetPin 6,DIN 'INTH,irqporta
SetPin 25,dout
vport=0
vport1=-1
vport2=0

I2C open 100,1000
Dim adr_mcp1=&h20
I2C write &h20,0,5,0,0,&hff,0,&hFF 'portA=output direct, portb=input inv
Pause(100)
I2C write &h20,0,2,&h0D,&hff 'pull up intB
'I2C close
Pause(500)
Print "begin prog"
Do
'I2C open 100,1000
I2C write &h20,0,2,&h12,&h55
Pin(25)=1
Pause(500)
I2C write &h20,0,2,&h12,&hAA
Pin(25)=0
Pause(500)
I2C write &h20,0,1,&h13
I2C read &h20,0,1,vport
'Print Hex$(vport)
If vport <> vport1 Then
vport1=vport
Print "scan rec:";Hex$(vport)
End if
'I2C close
Loop
End

but when I run, I have error

[35] End if
Error: Unexpected text


if I erase lines 32 to 35, I have no error
and it run corectly (blink is ok)
I Have read micromit's manual and I have no see that function "if/endif" is forbiden :-)
 
goc30

Guru

Joined: 12/04/2017
Location: France
Posts: 435
Posted: 05:04pm 19 Mar 2019
Copy link to clipboard 
Print this post

I have same bug with smaller prog without I2C functions
'test mcp23017
'TRON
Dim vport As integer
Dim vport1 As integer

SetPin 30,DIN 'INTH,irqporta
SetPin 31,dout
vport=0
vport1=-1

Pause(500)
Print "begin prog"
Do
Pin(31)=1
Pause(500)
Pin(31)=0
Pause(500)
If vport <> vport1 Then
vport1=vport
Print "scan rec:";Hex$(vport)
End if
Loop
End
 
CircuitGizmos

Guru

Joined: 08/09/2011
Location: United States
Posts: 1427
Posted: 05:05pm 19 Mar 2019
Copy link to clipboard 
Print this post

Try ENDIF as one word.

If that works, then END IF as two words is broken.


Micromites and Maximites! - Beginning Maximite
 
goc30

Guru

Joined: 12/04/2017
Location: France
Posts: 435
Posted: 05:37pm 19 Mar 2019
Copy link to clipboard 
Print this post

  CircuitGizmos said   Try ENDIF as one word.

If that works, then END IF as two words is broken.



yes with "ENDIF" it work correctly and with "END IF" it bug!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 08:28pm 19 Mar 2019
Copy link to clipboard 
Print this post

In version 4.6 changelog:
  Quote  END IF and ELSE IF can be used as alternatives to ENDIF and ELSEIF respectively

so the change came in just after your version.

Jim
VK7JH
MMedit
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1642
Posted: 09:16pm 19 Mar 2019
Copy link to clipboard 
Print this post

END IF does not work on the Maximite at the moment you must use ENDIF. It can be a bit confusing.

Bill
Keep safe. Live long and prosper.
 
CircuitGizmos

Guru

Joined: 08/09/2011
Location: United States
Posts: 1427
Posted: 09:21pm 19 Mar 2019
Copy link to clipboard 
Print this post

Here I always thought END IF was allowed, but TassyJim is right - it appeared in 4.6.

Micromites and Maximites! - Beginning Maximite
 
goc30

Guru

Joined: 12/04/2017
Location: France
Posts: 435
Posted: 09:39pm 19 Mar 2019
Copy link to clipboard 
Print this post

I don't see v4.6 for pic32mx250 (or pic32mx150)
where can I download??
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1642
Posted: 09:53pm 19 Mar 2019
Copy link to clipboard 
Print this post

I'm guessing that you have the latest version of MMBasic for that chip. I you want to use a later version I think you need to go to the MX170.

Bill
Keep safe. Live long and prosper.
 
CircuitGizmos

Guru

Joined: 08/09/2011
Location: United States
Posts: 1427
Posted: 10:03pm 19 Mar 2019
Copy link to clipboard 
Print this post

4.5E is the last version for the PIC32MX150F128 chip.
Micromites and Maximites! - Beginning Maximite
 
goc30

Guru

Joined: 12/04/2017
Location: France
Posts: 435
Posted: 02:23am 20 Mar 2019
Copy link to clipboard 
Print this post

  Turbo46 said   I'm guessing that you have the latest version of MMBasic for that chip. I you want to use a later version I think you need to go to the MX170.

Bill

I used this circuit because first I have several in my boxs and especially I wanted to test and understand the function of mcp23017 in "interrupt" mode, and it is not very simple

after when all is ok, I put the chip on my proto (with mx470)

for info, this is my final prog
'test mcp23017

Dim vport As integer
dim vportA as integer 'port for output LEDS
Dim vport1 As integer
Dim vport2 As integer
SetPin 11,INTL,irqportb
SetPin 13,dout
vport=0
vport1=-1
vport2=0
vportA=0

I2C open 100,1000
Dim adr_mcp1=&h20
'I2C write &h20,0,11,0,0,&hff,0,&hff,0,&hff ,0,&hff,0,&hff ',0,&hFF,0,&hFF
I2C write &h20,0,3,0,0,&hff 'IODIR portA=output, portB=input
I2C write &h20,0,3,2,0,&hff 'IPOL portA=sorties directes, portB=entrees inversees
I2C write &h20,0,3,4,0,&hff 'GPINTEN portA=disable interupt on input, portB=enable int sur entrees
I2C write &h20,0,2,7,&h00 'DEFVAL portB=compare
I2C write &h20,0,2,9,&h00 'INTCON portB=
I2C write &h20,0,3,&h0a,0,&h20 'IOCON portA=no int, portB=MIRROR+ODR+INTPOL
I2C write &h20,0,3,&h0c,0,&hFF 'GPPU portA=no pullup, portB=pullup
I2C write &h20,0,3,&h0e,0,&hff 'INTF portA=no int, portB=int
I2C write &h20,0,1,&h11 'read INTCAPB
I2C read &h20,0,1,vport 'init interrupt
Pause(500)
'i2c close
Print "begin prog"
I2C write &h20,0,1,&h13 'init GPIOB
I2C read &h20,0,1,vport1
pause(100)
Do
'I2C open 100,1000
vportA=(vportA xor 1) 'blink led
ecrportA
Pin(13)=1 'just to see if pic-prog run
Pause(500)
vportA=(vportA xor 1)
ecrportA
Pin(13)=0
Pause(500)
'i2c close
Loop
End

sub ecrporta
'I2C open 100,1000
I2C write &h20,0,2,&h12,vportA 'send to port A of mcp23017
I2C read &h20,0,1,vport1 'must read to valid int (why??)
'I2C close
end sub

Sub irqportb
'I2C open 100,1000
I2C write &h20,0,1,&h11 'read INTCAPB
I2C read &h20,0,1,vport2
'print vport2
if vport2<>0 then
if vport2=1 then vportA = (vportA or 2)
if vport2=2 then vportA = (vportA and &hFD)
ecrporta
'Print "irq rec: ";Hex$(vport2) ';" intcap:";hex$(vport1)
end if
I2C write &h20,0,1,&h13 'READ GPIO to init int
I2C read &h20,0,1,vport1
'I2C close
End Sub
Edited by goc30 2019-03-21
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025