[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  Electronics
. -> [Folder]  G-Pascal
. . -> [Subject]  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] Refresh page


Posted by Nick Gammon   Australia  (22,928 posts)  [Biography] 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
[Go to top] top

Posted by Fiendish   USA  (2,500 posts)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (22,928 posts)  [Biography] 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
[Go to top] 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.


5,529 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]