-
Categories
-
Platforms
-
Content
OK, no probs Kris. I fix that when I post the code.I don't think there's any need to drive the -RST inputs of the 595s, and again I suggest that you drive the display's -FL input from the micro until you know you won't need it.
;*********************************************************;
;* <- START OF PDSP PROGRAM -> *;
;*********************************************************;
;*********************************************************;
;* This program displays 'Hello!' on the PDSP2112 *;
;*********************************************************;
;***********************PIN_LAYOUT************************;
;* PIN___FUNCTION || PIN___FUNCTION || PIN___FUNCTION *;
;* C.4 -CE || C.2 -FL || C.1 -WR *;
;* C.0 -RST || B.2 SHFCLK 11|| B.3 LCHCLK 12 *;
;* B.4 SDI || || *;
;*********************************************************;
;*********************************************************;
;* This section is for renaming variables and constants *;
;*********************************************************;
symbol nCE=c.4
symbol nRST=c.0
symbol SDI=b.4
symbol nFL=c.2
symbol SHFCLK=b.2
symbol nWR=c.1
symbol LCHCLK=b.3
symbol TM=2 ;this will make all delays 5.7uS
;*********************************************************;
;* This is the main code which was made so it would *;
;* be easy to change what's on the display *;
;*********************************************************;
main: ;make all variables equal to zero only done once
let bit1=0
let bit2=0
let bit3=0
let bit4=0
let bit5=0
let bit6=0
let bit7=0
let bit8=0
let bit9=0
let bit10=0
let bit11=0
let bit12=0
let b10=0
goto start
start:
low SHFCLK,LCHCLK,SDI
high nCE,nWR,nRST,nFL ;a do nothing state
pauseus TM ;let it register
low nRST ;start the clear process
pauseus TM ;let it register
high nRST ;disable the rest pin
pauseus TM ;let it register
low nCE ;get access to the display
do ;start endless loop
let bit1=0 ; 'H' 100000011000
let bit2=0
let bit3=0
let bit4=1
let bit5=1
let bit6=0
let bit7=0
let bit8=0
let bit9=0
let bit10=0
let bit11=0
let bit12=1
gosub display
let bit1=0 ;'e' 010010101100
let bit2=0
let bit3=1
let bit4=1
let bit5=0
let bit6=1
let bit7=0
let bit8=1
let bit9=0
let bit10=0
let bit11=1
let bit12=0
gosub display
let bit1=0 ;'l' 110000111100
let bit2=0
let bit3=1
let bit4=1
let bit5=1
let bit6=1
let bit7=0
let bit8=0
let bit9=0
let bit10=0
let bit11=1
let bit12=1
gosub display
let bit1=0 ;'l' 001000111100
let bit2=0
let bit3=1
let bit4=1
let bit5=1
let bit6=1
let bit7=0
let bit8=0
let bit9=0
let bit10=1
let bit11=0
let bit12=0
gosub display
let bit1=0 ;'o' 101011111100
let bit2=0
let bit3=1
let bit4=1
let bit5=1
let bit6=1
let bit7=1
let bit8=1
let bit9=0
let bit10=1
let bit11=0
let bit12=1
gosub display
let bit1=0 ;'!' 011010000100
let bit2=0
let bit3=1
let bit4=0
let bit5=0
let bit6=0
let bit7=0
let bit8=1
let bit9=0
let bit10=1
let bit11=1
let bit12=0
gosub display
loop until b10=0 ;endless loop
;***************************************************;
;* this stores the data above in the shift *;
;* register/display. *;
;***************************************************;
display:
if bit1=1 then ;decide to load a 1 or 0 to the shift register
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
if bit2=1 then ;decide to load a 1 or 0 to the shift register
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
if bit3=1 then ;decide to load a 1 or 0 to the shift register
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
if bit4=1 then ;decide to load a 1 or 0 to the shift register
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
if bit5=1 then ;decide to load a 1 or 0 to the shift register
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
if bit6=1 then ;decide to load a 1 or 0 to the shift register
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
if bit7=1 then ;decide to load a 1 or 0 to the shift register
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
if bit8=1 then ;decide to load a 1 or 0 to the shift register
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
if bit9=1 then ;decide to load a 1 or 0 to the shift register
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
if bit10=1 then ;decide to load a 1 or 0 to the shift register
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
if bit11=1 then ;decide to load a 1 or 0 to the shift register
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
if bit12=1 then ;decide to load a 1 or 0 to the shift register
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
pauseus TM ;let it register
high LCHCLK ;load shift register to the output
pauseus TM ;let it register
low LCHCLK
pauseus TM ;let it register
low nWR ;put it on the PDSP2112
pauseus TM ;let it register
high nWR ;remove access from the display
pauseus TM ;let it register
;*********************************************************;
;* <- END OF PDSP PROGRAM -> *;
;*********************************************************;
;*********************************************************;
;* Version 1.0 Supercap2F *;
;*-------------------------------------------------------*;
;* Update list: *;
;* 1) - Code Complete - Supercap2F - 10/28/2014 *;
;* *;
;* *;
;* *;
;* *;
;*********************************************************;
Hey! I just learned about them a day or two ago in C! But I don't know if they will work with a PICAXE. I had a look over the commands and I didn't see anything that would work like they do.It would be far better to use a structure which wouldn't require you replicate the code so many times.
Ahh, a solution! I don't think you can do arrays with a PICAXE either. But! a integer will work! b0 and b1 are made of bit0-bit15 and w0 is made of b0 and b1. So I can set w0 to say, 2072 and it will make bit0-bit11 equal 100000011000, and set the display to 'H'. Is this what you had in mind? Assuming that it is, here's the code updated to have it:Two options are an array and an integer (or similar) large enough to hold the entire bit pattern.
;*********************************************************;
;* <- START OF PDSP PROGRAM -> *;
;*********************************************************;
;*********************************************************;
;* This program displays 'Hello!' on the PDSP2112 *;
;*********************************************************;
;***********************PIN_LAYOUT************************;
;* PIN___FUNCTION || PIN___FUNCTION || PIN___FUNCTION *;
;* C.4 -CE || C.2 -FL || C.1 -WR *;
;* C.0 -RST || B.2 SHFCLK 11|| B.3 LCHCLK 12 *;
;* B.4 SDI || || *;
;*********************************************************;
;*********************************************************;
;* This section is for renaming variables and constants *;
;*********************************************************;
symbol nCE=c.4
symbol nRST=c.0
symbol SDI=b.4
symbol nFL=c.2
symbol SHFCLK=b.2
symbol nWR=c.1
symbol LCHCLK=b.3
symbol TM=2 ;this will make all delays 5.7uS
;*********************************************************;
;* This is the main code which was made so it would *;
;* be easy to change what's on the display *;
;*********************************************************;
main: ;make all variables equal to zero only done once
let bit1=0
let bit2=0
let bit3=0
let bit4=0
let bit5=0
let bit6=0
let bit7=0
let bit8=0
let bit9=0
let bit10=0
let bit11=0
let bit12=0
let b10=0
goto start
start:
low SHFCLK,LCHCLK,SDI
high nCE,nWR,nRST,nFL ;a do nothing state
pauseus TM ;let it register
low nRST ;start the clear process
pauseus TM ;let it register
high nRST ;disable the rest pin
pauseus TM ;let it register
low nCE ;get access to the display
do ;start endless loop
let w0=2072 ;let w0=2072=100000011000='H'
gosub display
let w0=1196 ;let w0=1196=010010101100='e'
gosub display
let w0=3132 ;let w0=3132=110000111100='l'
gosub display
let w0=572 ;let w0=572=001000111100='l'
gosub display
let w0=2812 ;let w0=2812=101011111100='o'
gosub display
let w0=1668 ;let w0=1668=011010000100='!'
gosub display
loop until b10=0 ;endless loop
;***************************************************;
;* this stores the data above in the shift *;
;* register/display. *;
;***************************************************;
display:
if bit0=1 then ;decide to load a 1 or 0 to the shift register
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
if bit1=1 then ;decide to load a 1 or 0 to the shift register
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
if bit2=1 then ;decide to load a 1 or 0 to the shift register
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
if bit3=1 then ;decide to load a 1 or 0 to the shift register
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
if bit4=1 then ;decide to load a 1 or 0 to the shift register
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
if bit5=1 then ;decide to load a 1 or 0 to the shift register
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
if bit6=1 then ;decide to load a 1 or 0 to the shift register
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
if bit7=1 then ;decide to load a 1 or 0 to the shift register
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
if bit8=1 then ;decide to load a 1 or 0 to the shift register
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
if bit9=1 then ;decide to load a 1 or 0 to the shift register
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
if bit10=1 then ;decide to load a 1 or 0 to the shift register
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
if bit11=1 then ;decide to load a 1 or 0 to the shift register
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
pauseus TM ;let it register
high LCHCLK ;load shift register to the output
pauseus TM ;let it register
low LCHCLK
pauseus TM ;let it register
low nWR ;put it on the PDSP2112
pauseus TM ;let it register
high nWR ;remove access from the display
pauseus TM ;let it register
;*********************************************************;
;* <- END OF PDSP PROGRAM -> *;
;*********************************************************;
;*********************************************************;
;* Version 1.0 Supercap2F *;
;*-------------------------------------------------------*;
;* Update list: *;
;* 1) - Code Complete - Supercap2F - 10/28/2014 *;
;* 2) - Simplified the code - Supercap2F -10/28/2014 *;
;* *;
;* *;
;* *;
;*********************************************************;
I wondered if there might be a way to make that repeated code simpler! That w0=w0/2 bit shift thing is super cool! Here's the code updated to have it:You can shorten the display subroutine by using a loop. You need another variable (byte-sized) for the loop counter. Each time through the loop, you set SDI according to the state of bit0 and toggle SHFCLK, then you shift all the bits down, so the value that was in b1 is now in b0, and so on. You can do this bit-shifting magically with a single statement: "let w0 = w0 / 2". I'm sure you can figure out why this will work. Then you decrement your loop counter and loop if it's not zero. (I think PICAXE has FOR or WHILE loops, doesn't it?)
;*********************************************************;
;* <- START OF PDSP PROGRAM -> *;
;*********************************************************;
;*********************************************************;
;* This program displays 'Hello!' on the PDSP2112 *;
;*********************************************************;
;***********************PIN_LAYOUT************************;
;* PIN___FUNCTION || PIN___FUNCTION || PIN___FUNCTION *;
;* C.4 -CE || C.2 -FL || C.1 -WR *;
;* C.0 -RST || B.2 SHFCLK 11|| B.3 LCHCLK 12 *;
;* B.4 SDI || || *;
;*********************************************************;
;*********************************************************;
;* This section is for renaming variables and constants *;
;*********************************************************;
symbol nCE=c.4
symbol nRST=c.0
symbol SDI=b.4
symbol nFL=c.2
symbol SHFCLK=b.2
symbol nWR=c.1
symbol LCHCLK=b.3
symbol TM=2 ;this will make all delays 5.7uS
;*********************************************************;
;* This is the main code which was made so it would *;
;* be easy to change what's on the display *;
;*********************************************************;
main: ;make all variables equal to zero only done once
let bit1=0
let bit2=0
let bit3=0
let bit4=0
let bit5=0
let bit6=0
let bit7=0
let bit8=0
let bit9=0
let bit10=0
let bit11=0
let bit12=0
let b10=0
goto start
start:
low SHFCLK,LCHCLK,SDI
high nCE,nWR,nRST,nFL ;a do nothing state
pauseus TM ;let it register
low nRST ;start the clear process
pauseus TM ;let it register
high nRST ;disable the rest pin
pauseus TM ;let it register
low nCE ;get access to the display
do ;start endless loop
let w0=2072 ;let w0=2072=100000011000='H'
gosub display
let w0=1196 ;let w0=1196=010010101100='e'
gosub display
let w0=3132 ;let w0=3132=110000111100='l'
gosub display
let w0=572 ;let w0=572=001000111100='l'
gosub display
let w0=2812 ;let w0=2812=101011111100='o'
gosub display
let w0=1668 ;let w0=1668=011010000100='!'
gosub display
loop until b10=0 ;endless loop
;***************************************************;
;* this stores the data above in the shift *;
;* register/display. *;
;***************************************************;
display:
let b2=0 ;start loop value
do ;start loop
if bit0=1 then
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
let w0=w0/2 ;shift value down one place
inc b2 ;let b2=b2+1 so the loop will work right
loop until b2=11
pauseus TM ;let it register
high LCHCLK ;load shift register to the output
pauseus TM ;let it register
low LCHCLK
pauseus TM ;let it register
low nWR ;put it on the PDSP2112
pauseus TM ;let it register
high nWR ;remove access from the display
pauseus TM ;let it register
return
;*********************************************************;
;* <- END OF PDSP PROGRAM -> *;
;*********************************************************;
;*******************************************************************;
;* Version 1.0 Supercap2F *;
;*-----------------------------------------------------------------*;
;* Update list: *;
;* 1) - Code Complete - Supercap2F - 10/28/2014 *;
;* 2) - Simplified the main code - Supercap2F - 10/28/2014 *;
;* 3) - Simplified the display code - Supercap2F - 10/28/2014 *;
;* *;
;* *;
;*******************************************************************;
Ahh yes, I missed that. Code updated to have it. I tried the "let SDI=bit0" like you said, but it gave me an error. Here's the code:The initialisation code can just say w0 = 0 instead of setting bit0~bit12 to 0 individually.
I think you should be able to change the "if bit0=1 then high SDI else low SDI" to something straightforward like "let SDI = bit0". Not sure though.
;*********************************************************;
;* <- START OF PDSP PROGRAM -> *;
;*********************************************************;
;*********************************************************;
;* This program displays 'Hello!' on the PDSP2112 *;
;*********************************************************;
;***********************PIN_LAYOUT************************;
;* PIN___FUNCTION || PIN___FUNCTION || PIN___FUNCTION *;
;* C.4 -CE || C.2 -FL || C.1 -WR *;
;* C.0 -RST || B.2 SHFCLK 11|| B.3 LCHCLK 12 *;
;* B.4 SDI || || *;
;*********************************************************;
;*********************************************************;
;* This section is for renaming variables and constants *;
;*********************************************************;
symbol nCE=c.4
symbol nRST=c.0
symbol SDI=b.4
symbol nFL=c.2
symbol SHFCLK=b.2
symbol nWR=c.1
symbol LCHCLK=b.3
symbol TM=2 ;this will make all delays 5.7uS
;*********************************************************;
;* This is the main code which was made so it would *;
;* be easy to change what's on the display *;
;*********************************************************;
main: ;make all variables equal to zero only done once
let w0=0
let b2=0
goto start
start:
low SHFCLK,LCHCLK,SDI
high nCE,nWR,nRST,nFL ;a do nothing state
pauseus TM ;let it register
low nRST ;start the clear process
pauseus TM ;let it register
high nRST ;disable the rest pin
pauseus TM ;let it register
low nCE ;get access to the display
do ;start endless loop
let w0=2072 ;let w0=2072=100000011000='H'
gosub display
let w0=1196 ;let w0=1196=010010101100='e'
gosub display
let w0=3132 ;let w0=3132=110000111100='l'
gosub display
let w0=572 ;let w0=572=001000111100='l'
gosub display
let w0=2812 ;let w0=2812=101011111100='o'
gosub display
let w0=1668 ;let w0=1668=011010000100='!'
gosub display
loop until b10=0 ;endless loop
;***************************************************;
;* this stores the data above in the shift *;
;* register/display. *;
;***************************************************;
display:
let b2=0 ;start loop value
do ;start loop
if bit0=1 then
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
let w0=w0/2 ;shift value down one place
inc b2 ;let b2=b2+1 so the loop will work right
loop until b2=11
pauseus TM ;let it register
high LCHCLK ;load shift register to the output
pauseus TM ;let it register
low LCHCLK
pauseus TM ;let it register
low nWR ;put it on the PDSP2112
pauseus TM ;let it register
high nWR ;remove access from the display
pauseus TM ;let it register
return
;*********************************************************;
;* <- END OF PDSP PROGRAM -> *;
;*********************************************************;
;*******************************************************************;
;* Version 1.0 Supercap2F *;
;*-----------------------------------------------------------------*;
;* Update list: *;
;* 1) - Code Complete - Supercap2F - 10/28/2014 *;
;* 2) - Simplified the main code - Supercap2F - 10/28/2014 *;
;* 3) - Simplified the display code - Supercap2F - 10/29/2014 *;
;* 4) - Updated the veriables initialisation - Supercap2F - 10/29/2014 *;
;* *;
;*******************************************************************;
Yeah, I had a feeling that's the way it worked. But having them initialized does help me keep track of what variables have been used.There's no actual need to initialise w0 and b2. They are both set before they are used.
Yeah, I guess it would make more since to have first bit to correspond to A3 and the fourth bit to correspond to A0, should I switch them around in the schematic? Should I switch around D0-D7 too?When you set w0 to various values - 2072, 1196, 3132 etc - you can actually specify the values in binary using a '%' prefix: w0 = %100000011000 ; 'H'
Let's look at the mapping of the bits in those values. The first four bits specify the position for the character to be displayed at, right? But the bits seem to be backwards. I would expect the first bit to correspond to A3 and the fourth bit to correspond to A0. Then the other eight bits specify the character to write. Are they in the right order? You can re-order those bits by changing the hardware, or by sending the bits in the opposite order inside the display subroutine.
Ahh, yes! That would make the code more reader friendly. But shouldn't we make b0 equal the character and b1 equal the position? Because if we don't... Well let's say b0 equals the position and it's position one (0001) the byte is really 8 bits so it really equals 00000001. Then we add the character (say 00011000) so w0 would equal 0001100000000001 (since b0 comes before b1) which would be wrong. But if we make b1 equal the position it would be 0000000100011000 in other words 000100011000.How about splitting up the display subroutine's parameter into a position byte and a character byte. This would make the display subroutine easier to use, and make the code clearer. Instead of converting "H at position 1" into %100000011000, you could just say b0 = 1 (position) and b1 = "H" (character). That makes it easier to follow the code, easier to write it, and easier to change it without making mistakes.
Separating the character and position into separate variables also makes it a lot easier to implement a scrolling display, if you want to do that in future.
OK, will try and edit the variables names/comments better in the next code update.The PICAXE programming "language" and environment are pretty simple and not very well designed, but you can improve your program's robustness in various ways. One weakness of the environment is the global variables. It's easy to double-book a variable - i.e. use it for two different things in such a way that when you call a subroutine, a variable that you were relying on gets overwritten. The b2 variable is a good example here.
A simple comment like "Destroys b2" in the display subroutine can help, but you can also explicitly allocate and name variables early on in your program, using comments to say which subroutines and code sections use the variable. For example you could say "'SYMBOL display_bit_looper b2". Have a look at the PICAXE code I wrote for your chicken coop door controller to see how I documented the variable allocation there.
Hey it's not me, I'm just doing what Kris said.Well, that's shorter and nicer code. Good one SuperCap2F!
OK, got it.It's better to keep track of the used/unused variables in a separate section before the code, using (for PICAXE) the SYMBOL statement to allocate them.
I thought right now I was sending it MSB first? The way it's set up now it sends 'H' as 100000011000 which would be 1000 as the address:It's traditional (but not universal) for serial interfaces to send data LSB (least significant bit) first. That's how your code works at the moment. So you could keep your code the same, and reverse the bit allocations in hardware, yes. But you don't have to. A few comments in your code will clarify what the hardware does and how the bits are mapped to the data and address signals for the display module.
You're probably right about the byte ordering, and that makes sense if you're sending all 12 bits in a single loop, accessing them as w0. I was thinking it might be slightly clearer for the display subroutine to send eight bits from the character variable in one loop, then send the four bits from the position variable in a separate loop. But there's no need to do it that way.
Also now that you're not accessing w0 as separate bits, you could use w2 (aka b4 and b5) instead of w0, so those bits are available for possible future use, instead of being unusable for no good reason.
1248-1248...
1000-00011000
|--|
location
|------|
Letter
| LBS
| LBS
F E D C B A 9 8 7 6 5 4 3 2 1 0 (bits in w2)
7 6 5 4 3 2 1 0 . . . . . . . . (bits in b5)
. . . . . . . . 7 6 5 4 3 2 1 0 (bits in b4)
* . . . . . . . . . . . . . . . U1.QA - available for future use
. * . . . . . . . . . . . . . . U1.QB: -CE to PDSP2110
. . * . . . . . . . . . . . . . U1.QC: -RST to PDSP2110
. . . * . . . . . . . . . . . . U1.QD: -FL to PDSP2110
. . . . * * * * . . . . . . . . Character position:
. . . . * . . . . . . . . . . . U1.QE: char position, bit 3 (A3 to PDSP2110)
. . . . . * . . . . . . . . . . U1.QF: char position, bit 2 (A2 to PDSP2110)
. . . . . . * . . . . . . . . . U1.QG: char position, bit 1 (A1 to PDSP2110)
. . . . . . . * . . . . . . . . U1.QH: char position, bit 0 (A0 to PDSP2110)
. . . . . . . . * * * * * * * * Character:
. . . . . . . . * . . . . . . . U2.QA: character, bit 7 (D7 to PDSP2110)
. . . . . . . . . * . . . . . . U2.QB: character, bit 6 (D6 to PDSP2110)
. . . . . . . . . . * . . . . . U2.QC: character, bit 5 (D5 to PDSP2110)
. . . . . . . . . . . * . . . . U2.QD: character, bit 4 (D4 to PDSP2110)
. . . . . . . . . . . . * . . . U2.QE: character, bit 3 (D3 to PDSP2110)
. . . . . . . . . . . . . * . . U2.QF: character, bit 2 (D2 to PDSP2110)
. . . . . . . . . . . . . . * . U2.QG: character, bit 1 (D1 to PDSP2110)
. . . . . . . . . . . . . . . * U2.QH: character, bit 0 (D0 to PDSP2110)
K, no probs. So should we just leave -CE how it is now, and if it doesn't work worry about it then?So I've suggested redefining the connection between the shift registers and the PDSP2110, and I've sneaked in -CE, -RST and -FL being driven from the shift registers as well. This is because those signals don't need to change very often. Only -WR needs to be pulsed briefly, to execute the write operation once the other states are set up. The initial reset only needs to be done once, and -FL is tied in with the address and data lines anyway.
You might want or need to keep -CE driven directly from the micro, so you can quickly deselect the PDSP2110 when the access has finished, since you may find that you need to raise -CE in between writes for the PDSP to work properly. (Your code currently leaves -CE low in between accesses to different addresses in the PDSP2110, but this may not work properly when you test it.)
I tried using the "if (w2 & 1) = 1 then high SDI else low SDI endif" thing, but it gave me an "syntax" error on the "if (w2 & 1)" part. I can't think of anything to to but use w0 instead... Do you know of anything to do? Here's the code:Once you change to using w2 instead of w0, in your loop in the display subroutine you will have to change the test "if bit0 = 1 then high SDI else low SDI endif" to "if (w2 & 1) = 1 then high SDI else low SDI endif" because you can no longer access bit 0 of the 16-bit data value as a bit variable.
;*********************************************************;
;* <- START OF PDSP PROGRAM -> *;
;*********************************************************;
;*********************************************************;
;* This program displays 'Hello!' on the PDSP2112 *;
;*********************************************************;
;F E D C B A 9 8 7 6 5 4 3 2 1 0 (bits in w2)
;7 6 5 4 3 2 1 0 . . . . . . . . (bits in b5)
;. . . . . . . . 7 6 5 4 3 2 1 0 (bits in b4)
;* . . . . . . . . . . . . . . . U1.QA - available for future use
;. * . . . . . . . . . . . . . . U1.QB: -CE to PDSP2110
;. . * . . . . . . . . . . . . . U1.QC: -RST to PDSP2110
;. . . * . . . . . . . . . . . . U1.QD: -FL to PDSP2110
;. . . . * * * * . . . . . . . . Character position:
;. . . . * . . . . . . . . . . . U1.QE: char position, bit 3 (A3 to PDSP2110)
;. . . . . * . . . . . . . . . . U1.QF: char position, bit 2 (A2 to PDSP2110)
;. . . . . . * . . . . . . . . . U1.QG: char position, bit 1 (A1 to PDSP2110)
;. . . . . . . * . . . . . . . . U1.QH: char position, bit 0 (A0 to PDSP2110)
;. . . . . . . . * * * * * * * * Character:
;. . . . . . . . * . . . . . . . U2.QA: character, bit 7 (D7 to PDSP2110)
;. . . . . . . . . * . . . . . . U2.QB: character, bit 6 (D6 to PDSP2110)
;. . . . . . . . . . * . . . . . U2.QC: character, bit 5 (D5 to PDSP2110)
;. . . . . . . . . . . * . . . . U2.QD: character, bit 4 (D4 to PDSP2110)
;. . . . . . . . . . . . * . . . U2.QE: character, bit 3 (D3 to PDSP2110)
;. . . . . . . . . . . . . * . . U2.QF: character, bit 2 (D2 to PDSP2110)
;. . . . . . . . . . . . . . * . U2.QG: character, bit 1 (D1 to PDSP2110)
;. . . . . . . . . . . . . . . * U2.QH: character, bit 0 (D0 to PDSP2110)
;***********************PIN_LAYOUT************************;
;* PIN___FUNCTION || PIN___FUNCTION || PIN___FUNCTION *;
;* C.0 SDI || C.1 LCHCLK 12|| C.2 SHFCLK 11 *;
;* B.1 -WR || || *;
;*********************************************************;
;*********************************************************;
;* This section is for renaming variables and constants *;
;*********************************************************;
symbol SDI=c.0
symbol SHFCLK=c.2
symbol nWR=b.1
symbol LCHCLK=c.1
symbol TM=2 ;this will make all delays 5.7uS
;*********************************************************;
;* This is the main code which was made so it would *;
;* be easy to change what's on the display *;
;*********************************************************;
main:
let b5=%01110000 ;high nCE,nRST,nFL
high nWR
low SHFCLK,LCHCLK,SDI
gosub display ;a do nothing state
let b5=%01010000 ;low nRST
gosub display ;start the clear process
let b5=%01110000 ;high nRST
gosub display ;disable the reset pin
let b5=%00110000 ;low nCE
gosub display ;get access to the display
do ;start endless loop
let b5=%00110001 ;high nFL, nRST. address #1
let b4=%00011000 ;character 'H'
gosub display
gosub load_on_screen
let b5=%00110010 ;high nFL, nRST. address #2
let b4=%01100101 ;character 'e'
gosub display
gosub load_on_screen
let b5=%00110011 ;high nFL, nRST. address #3
let b4=%01101100 ;character 'l'
gosub display
gosub load_on_screen
let b5=%00110100 ;high nFL, nRST. address #4
let b4=%01101100 ;character 'l'
gosub display
gosub load_on_screen
let b5=%00110101 ;high nFL, nRST. address #5
let b4=%01101111 ;character 'l'
gosub display
gosub load_on_screen
let b5=%00110011 ;high nFL, nRST. address #3
let b4=%00100001 ;character '!'
gosub display
gosub load_on_screen
loop until b10=10 ;endless loop
;***************************************************;
;* this stores the data above in the shift *;
;* register. *;
;***************************************************;
display:
let b2=0 ;start loop value
do ;start loop
if (w2 & 1)=1 then ;ERROR HERE!!
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
let w2=w2/2 ;shift value down one place
inc b2 ;let b2=b2+1 so the loop will work right
loop until b2=16
pauseus TM ;let it register
high LCHCLK ;load shift register to the output
pauseus TM ;let it register
low LCHCLK
pauseus TM ;let it register
return
;*********************************************************;
;* This loads the data in the shift register to the *;
;* screen. *;
;*********************************************************;
load_on_screen:
pauseus TM ;let it register
low nWR ;put it on the PDSP2112
pauseus TM ;let it register
high nWR ;remove access from the display
pauseus TM ;let it register
return
;*********************************************************;
;* <- END OF PDSP PROGRAM -> *;
;*********************************************************;
;*******************************************************************;
;* Version 1.0 Supercap2F *;
;*-----------------------------------------------------------------*;
;* Update list: *;
;* 1) - Code Complete - Supercap2F - 10/28/2014 *;
;* 2) - Simplified the main code - Supercap2F - 10/28/2014 *;
;* 3) - Simplified the display code - Supercap2F - 10/28/2014 *;
;* 4) - Changed pin layout. And made code more robust *;
;* Supercap2F - 10/30/2014 *;
;* *;
;*******************************************************************;
Yeah, it bugged me all night trying to think of a way to do it in my sleep. Lol!Re isolating bit 0 of the data word. The "if (w2 & 1) = 1" is not allowed in PICAXE language because it's too complicated! There might be ways around it, but it's simplest to go back to using w0 (r0 for the character and r1 for the position and control signals) and testing bit0.
No I don’t have it on a breadboard yet. Should I lay it out now?I'm not sure how best to deal with -CE. Do you have your code working on a breadboard prototype?
Did you see I changed the display subroutine? I put the part that pluses –WR low in a new subroutine called “load_on_screen” and I only called it when I was changing the characters.Now that we're controlling -RST from the shift register, your startup code needs to call the display subroutine to send values to the shift register, to bring -RST low then return it high again at startup. But the display subroutine also pulses -WR low. I notice that you set the four address bits to all zeros for that case, and I guess that will cause a dummy write because address 0000 doesn't do anything, right? So it probably won't cause any problems, but it's not strictly right.
This is pretty much what I did when I added the “load_on_screen” subroutine. Sorry I should have said something about it in post #37. It is a little different then what you suggested, so have a look over it and tell me what you think.I suggest you add another subroutine called displaychar, and rename the existing subroutine to write_sr (write shift register) or something similar. displaychar needs to call write_sr, but write_sr should only write the 16-bit data to the shift register; move the code that pulses -WR low from the write_sr subroutine into the displaychar subroutine.
;*********************************************************;
;* <- START OF PDSP PROGRAM -> *;
;*********************************************************;
;*********************************************************;
;* This program displays 'Hello!' on the PDSP2112 *;
;*********************************************************;
;F E D C B A 9 8 7 6 5 4 3 2 1 0 (bits in w0)
;7 6 5 4 3 2 1 0 . . . . . . . . (bits in b1)
;. . . . . . . . 7 6 5 4 3 2 1 0 (bits in b0)
;* . . . . . . . . . . . . . . . U1.QA - available for future use
;. * . . . . . . . . . . . . . . U1.QB: -CE to PDSP2110
;. . * . . . . . . . . . . . . . U1.QC: -RST to PDSP2110
;. . . * . . . . . . . . . . . . U1.QD: -FL to PDSP2110
;. . . . * * * * . . . . . . . . Character position:
;. . . . * . . . . . . . . . . . U1.QE: char position, bit 3 (A3 to PDSP2110)
;. . . . . * . . . . . . . . . . U1.QF: char position, bit 2 (A2 to PDSP2110)
;. . . . . . * . . . . . . . . . U1.QG: char position, bit 1 (A1 to PDSP2110)
;. . . . . . . * . . . . . . . . U1.QH: char position, bit 0 (A0 to PDSP2110)
;. . . . . . . . * * * * * * * * Character:
;. . . . . . . . * . . . . . . . U2.QA: character, bit 7 (D7 to PDSP2110)
;. . . . . . . . . * . . . . . . U2.QB: character, bit 6 (D6 to PDSP2110)
;. . . . . . . . . . * . . . . . U2.QC: character, bit 5 (D5 to PDSP2110)
;. . . . . . . . . . . * . . . . U2.QD: character, bit 4 (D4 to PDSP2110)
;. . . . . . . . . . . . * . . . U2.QE: character, bit 3 (D3 to PDSP2110)
;. . . . . . . . . . . . . * . . U2.QF: character, bit 2 (D2 to PDSP2110)
;. . . . . . . . . . . . . . * . U2.QG: character, bit 1 (D1 to PDSP2110)
;. . . . . . . . . . . . . . . * U2.QH: character, bit 0 (D0 to PDSP2110)
;***********************PIN_LAYOUT************************;
;* PIN___FUNCTION || PIN___FUNCTION || PIN___FUNCTION *;
;* C.0 SDI || C.1 LCHCLK 12|| C.2 SHFCLK 11 *;
;* B.1 -WR || || *;
;*********************************************************;
;*********************************************************;
;* This section is for renaming variables and constants *;
;*********************************************************;
symbol SDI=c.0
symbol SHFCLK=c.2
symbol nWR=b.1
symbol LCHCLK=c.1
symbol TM=2 ;this will make all delays 5.7uS
;*********************************************************;
;* This is the main code which was made so it would *;
;* be easy to change what's on the display *;
;*********************************************************;
main:
let b1=%01110000 ;high nCE,nRST,nFL
high nWR
low SHFCLK,LCHCLK,SDI
gosub display ;a do nothing state
let b1=%01010000 ;low nRST
gosub display ;start the clear process
let b1=%01110000 ;high nRST
gosub display ;disable the reset pin
let b1=%00110000 ;low nCE
gosub display ;get access to the display
do ;start endless loop
let b1=%00110001 ;high nFL, nRST. address #1
let b0=%00011000 ;character 'H'
gosub display
gosub load_on_screen
let b1=%00110010 ;high nFL, nRST. address #2
let b0=%01100101 ;character 'e'
gosub display
gosub load_on_screen
let b1=%00110011 ;high nFL, nRST. address #3
let b0=%01101100 ;character 'l'
gosub display
gosub load_on_screen
let b1=%00110100 ;high nFL, nRST. address #4
let b0=%01101100 ;character 'l'
gosub display
gosub load_on_screen
let b1=%00110101 ;high nFL, nRST. address #5
let b0=%01101111 ;character 'l'
gosub display
gosub load_on_screen
let b1=%00110011 ;high nFL, nRST. address #3
let b0=%00100001 ;character '!'
gosub display
gosub load_on_screen
loop until b10=10 ;endless loop
;***************************************************;
;* this stores the data above in the shift *;
;* register. *;
;***************************************************;
display:
let b2=0 ;start loop value
do ;start loop
if bit1=1 then
high SDI
else
low SDI
endif
pauseus TM ;let it register
high SHFCLK ;load value to shift register
pauseus TM ;let it register
low SHFCLK
let w2=w2/2 ;shift value down one place
inc b2 ;let b2=b2+1 so the loop will work right
loop until b2=16
pauseus TM ;let it register
high LCHCLK ;load shift register to the output
pauseus TM ;let it register
low LCHCLK
pauseus TM ;let it register
return
;*********************************************************;
;* This loads the data in the shift register to the *;
;* screen. *;
;*********************************************************;
load_on_screen:
pauseus TM ;let it register
low nWR ;put it on the PDSP2112
pauseus TM ;let it register
high nWR ;remove access from the display
pauseus TM ;let it register
return
;*********************************************************;
;* <- END OF PDSP PROGRAM -> *;
;*********************************************************;
;*******************************************************************;
;* Version 1.0 Supercap2F *;
;*-----------------------------------------------------------------*;
;* Update list: *;
;* 1) - Code Complete - Supercap2F - 10/28/2014 *;
;* 2) - Simplified the main code - Supercap2F - 10/29/2014 *;
;* 3) - Simplified the display code - Supercap2F - 10/29/2014 *;
;* 4) - Changed pin layout. And made code more robust *;
;* Supercap2F - 10/30/2014 *;
;* 5) - Changed varaibles back to how they where - Supercap2F *;
;* - 10/31/14 *;
;* *;
;*******************************************************************;