they are good opinions and I
they are good opinions and I thinkk the best thing to do on the pin amounts would be to arange the pins in order as
- V+
- V-
- SDA
- SCL
- Signal
so that you can have the 5 or 3 pin layout.
also the pulup resistor idea is wise. I cant remember my logic on why I had it this way but I see the reason not too and will change that
Thnx
Tgeahre
Magic
Looks like we have a plan, then. Have you devised a protocol? I’m going to write this up on the boards later, but I’m thinking that the master will be able to inspect or modify any 8-bit address in the slave using the following conversation:
1) The bus master sends a 3 (or 4) byte message consisting of:
- the address of the slave device
- a command byte (13 = byte read, 14 = byte write)
- the address of the data within the slave (in a nromal pic,this would just be a GPR address)
- in the case of a write command, the data byte is sent
2) The slave responds with the data byte. Where the command was read, this is the data read. Where the command was write, this is the data written.
The reasons are historical. This is a subset of an existing protocol and may be expanded later to include bit read / write, byte read / write commands. My protocol has a lot more functionality including code jumps, but this is enough to get started.
What say ye?
well so far I wasn’t
well so far I wasn’t planning on having the master write to the slave in this but I think I can come up with some nice things that could be helpful for it so I’ll look that over later. what I do have though is rather nice I think. I haven’t finnished the code as I don’t know everything about I2C communication that I want yet but I am still reading up on it. I have finnished the program to print the numbers on the screen though it’s not tested. I don’t have the XOR so I cant really test it yet.
Here is the code I have:
symbol adc = b1
symbol seg1 = b2
symbol seg2 = b3
symbol num = b4
symbol latch = pin4
’reset
init:
let num = 00
goto add0
scan:
readadc 3, adc
if adc < 50 then scan
if adc < 57 then add1
if adc < 62 then add2
if adc < 68 then add3
if adc < 75 then add4
if adc < 80 then add5
if adc < 90 then add6
if adc < 104 then add7
if adc < 120 then add8
if adc < 140 then add9
if adc < 180 then init
if adc < 220 then add0
if adc = 255 then send
goto scan
’sets latches and routs to digit setting subroutines
display:
let latch = 1
on seg2 gosub led0, led1, led2, led3, led4, led5, led6, led7, led8, led9
let latch = 0
on seg1 gosub led0, led1, led2, led3, led4, led5, led6, led7, led8, led9
goto scan
’to i2c
send:
'use I2C to send num to the master uProcessor
goto scan
’Calculates num. outputs to display to set the 7segs.
add0:
num = num % 10
num = num * 10
seg1 = num % 10
seg2 = num / 10
goto display
add1:
num = num % 10
num = num * 10 + 1
seg1 = num % 10
seg2 = num / 10
goto display
add2:
num = num % 10
num = num * 10 + 2
seg1 = num % 10
seg2 = num / 10
goto display
add3:
num = num % 10
num = num * 10 + 3
seg1 = num % 10
seg2 = num / 10
goto display
add4:
num = num % 10
num = num * 10 + 4
seg1 = num % 10
seg2 = num / 10
goto display
add5:
num = num % 10
num = num * 10 + 5
seg1 = num % 10
seg2 = num / 10
goto display
add6:
num = num % 10
num = num * 10 + 6
seg1 = num % 10
seg2 = num / 10
goto display
add7:
num = num % 10
num = num * 10 + 7
seg1 = num % 10
seg2 = num / 10
goto display
add8:
num = num % 10
num = num * 10 + 8
seg1 = num % 10
seg2 = num / 10
goto display
add9:
num = num % 10
num = num * 10 + 9
seg1 = num % 10
seg2 = num / 10
goto display
’set 7segs
led0:
let pins = %00000000 & %00001111
return
led1:
let pins = %00000001 & %00001111
return
led2:
let pins = %00000010 & %00001111
return
led3:
let pins = %00000011 & %00001111
return
led4:
let pins = %00000100 & %00001111
return
led5:
let pins = %00000101 & %00001111
return
led6:
let pins = %00000110 & %00001111
return
led7:
let pins = %00000111 & %00001111
return
led8:
let pins = %00001000 & %00001111
return
led9:
let pins = %00001001 & %00001111
return
as you can see, if you are good at reading code, it is made to start with the number 00. then you push a key, lets say 5, and the number is 05. push 6 and it is 56. push 9 and the number is 69. you get the idea. I only have to come up with the I2C section. I have the signal pin set up so that it can be used as an interuptor, but that is probably a crude way of doing it. do you know what I meen by using it as an interuptor? is it crude? is there a better way?
Back to the Future
I don’t use BASIC on a PIC. I’ve done this sort of thing before in PIC RISC and an “interrupt on PORTB change” is the best way.
In RISC, you have a piece of code at the interrupt vector (address 0x0004) which looks for the RBIF bit of the INTCON register going high. That’s how you know SOMETHING on PORTB has changed.
Have you considered “debounce”? I suspect that the code will execute so quickly that when you press a key the PIC will think you’ve pressed it about 5 times. Once the interrupt takes place, I suggest you pause for about 20ms before actually processing it.
that is agood idea, I’ll
that is agood idea, I’ll look into the debounce idea when I finally get my XOR and can actually try it.
I don’t know currently how to program pics in other languages. the important thing is that you agree on the interupt pin as a method of telling the master that a number has been submited using the submit key (pound #).
I’ll finnish my readings on I2C communication and update my code.
Me neither
Hehe. Nor do I. Which is why I can only say that’s what I’d do in assembler. For all I know the inputs could already be debounced by the BASIC compiler. Perhaps someone who’s read the manual could tell us.