Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ Electronics ➜ G-Pascal ➜ I2C support added to the G-Pascal EEPROM

I2C support added to the G-Pascal EEPROM

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Nick Gammon   Australia  (23,121 posts)  Bio   Forum Administrator
Date Sat 05 Mar 2022 01:17 AM (UTC)

Amended on Sat 05 Mar 2022 08:13 PM (UTC) by Nick Gammon

Message
Support for I2C devices has been added to version 4.01 of the G-Pascal system. The video below shows a MCP23017 port-expander controlling 16 LEDs under instruction from some simple code written in Assembler.




Documentation about it at http://www.gammon.com.au/G-Pascal/i2c.htm

Code used in above demo:


; I2C testing of MCP23017 port-expander
;

  jmp begin      ; skip the variables

; MCP23017 registers

IODIRA   = $00   ; IO direction  (0 = output, 1 = input (Default))
IOCON    = $0A   ; IO Configuration: bank/mirror/seqop/disslw/haen/odr/intpol/notimp
GPIOA    = $12   ; Port value. Write to change, read to obtain value

;
;  Change this depending on how you set up the address jumpers. Value $20 to $27
;
PORT     = $27  ; MCP23017 is on I2C port 0x27

;                            register value A    value B
io_configuration_message  dfb IOCON,  %00100000, %00100000  ; byte mode (not sequential)
io_direction_message      dfb IODIRA, $0,        $0         ; 1 = input, 0 = output
io_output_message         dfb GPIOA,  $22,       $00        ; a pattern to show on the LEDs

failure_message   string "Got NAK\n"
starting_message  string "Starting I2C port-expander test\n"

;---------------------------------------------
;  BEGIN code execution
;---------------------------------------------

begin:
  lda #<starting_message
  ldx #>starting_message
  jsr print

  jsr i2c_init

;
;  configuration
;
  lda #<io_configuration_message
  sta VALUE
  lda #>io_configuration_message
  sta VALUE+1
  ldy #3
  lda #PORT
  jsr i2c_send
  bcc i2c_failure


;
;  Set ports to output
;

  lda #<io_direction_message
  sta VALUE
  lda #>io_direction_message
  sta VALUE+1
  ldy #3
  lda #PORT
  jsr i2c_send
  bcc i2c_failure

loop:

  jsr serial_available
  beq loop_no_key
  cmp #'C'-$40  ; ctrl+C?
  bne loop_no_key
  rts   ; we are done!

loop_no_key:

  lda #<io_output_message
  sta VALUE
  lda #>io_output_message
  sta VALUE+1
  ldy #3
  lda #PORT
  jsr i2c_send
  bcc i2c_failure

;
;  ripple pattern
;
  lda io_output_message+2
  ror a
  rol io_output_message+1
  rol io_output_message+2

loop_delay:
  ldx #<200
  ldy #>200
  jsr delay
  bra loop

i2c_failure:
  lda #<failure_message
  ldx #>failure_message
  jsr print
  bra loop_delay

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Fiendish   USA  (2,533 posts)  Bio   Global Moderator
Date Reply #1 on Sat 05 Mar 2022 05:23 PM (UTC)

Amended on Sat 05 Mar 2022 05:24 PM (UTC) by Fiendish

Message
Nick, you're supposed to do it in Pascal! ^_^

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Nick Gammon   Australia  (23,121 posts)  Bio   Forum Administrator
Date Reply #2 on Sat 05 Mar 2022 08:12 PM (UTC)
Message
I was waiting for someone to complain!

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


8,092 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.