not to mention the port pins are still analog ,difficult to see in all the noise
missed ALLDIGITAL in there , my case rests
not to mention the port pins are still analog ,difficult to see in all the noise
missed ALLDIGITAL in there , my case rests
Last edited by richard; - 10th August 2020 at 12:49.
Warning I'm not a teacher
Hi Henrik and Richard.
Many thanks for your prompt reply.
Really i'm not comfortable with programming, and i try to do what i really understand.
I think i solve the issue by changing the following lines to these.....
I wish i could manage to learn how to store values and read them after. I know that the code is not efficient at all.Code:chkey: if portb.0 = 1 and portb.1 = 0 and portb.2 = 0 and portb.3 = 0 and portb.4 = 0 then return if portb.0 = 1 and portb.1 = 1 and portb.2 = 0 and portb.3 = 0 and portb.4 = 0 then return if portb.0 = 1 and portb.1 = 1 and portb.2 = 1 and portb.3 = 0 and portb.4 = 0 then return if portb.0 = 1 and portb.1 = 1 and portb.2 = 1 and portb.3 = 1 and portb.4 = 0 then return if portb.0 = 1 and portb.1 = 1 and portb.2 = 1 and portb.3 = 1 and portb.4 = 1 then pwok
for now it works. I also change all the PORTX to LATX.
In the mean time i will try to learn and understand how to right values, then store them, read them and compare.
Many thanks once again.
if you have a simple strategy to solve a task the program comes easily i find
my strategy for this would be :-
monitor the serial input for 0x07 chr [the start of a transmission pkt]
when you get an 07 read in the pkt
(a pkt when received can be decoded [eg '070D0000313B' the 5th byte is the key value data the sixth is a simple xor checksum])
check if the 5th byte is bel [(0x08) the go button]
if it is not
place it in a password length sized ring buffer and continue monitoring the serial input
if it is
check if ring buffer contains the password key code sequence
if it does
then its a winner
else
object to the failed attempt
keep reading in data
Warning I'm not a teacher
i just can't help myself covid19 mania has set in
my take
Code:'* Notes : This is a codelock based on the following components * '* : PIC18F26K22 @ 64Mhz * '* : 4D Systems ULCD 32DT diablo * '* note chksum untested * '********************************************************************** #CONFIG CONFIG FOSC=INTIO67, PLLCFG=OFF, PRICLKEN=OFF, FCMEN=OFF, IESO=OFF CONFIG PWRTEN=OFF, BOREN=SBORDIS, BORV=190, WDTEN=ON, WDTPS=32768 CONFIG CCP2MX=PORTC1, PBADEN=OFF, CCP3MX=PORTB5, HFOFST=ON, T3CMX=PORTC0 CONFIG P2BMX=PORTB5, MCLRE=EXTMCLR, STVREN=ON, LVP=OFF, XINST=OFF, DEBUG=OFF CONFIG CP0=OFF, CP1=OFF, CP2=OFF, CP3=OFF, CPB=OFF, CPD=OFF, WRT0=OFF CONFIG WRT1=OFF, WRT2=OFF, WRT3=OFF, WRTC=OFF, WRTB=OFF, WRTD=OFF, EBTR0=OFF CONFIG EBTR1=OFF, EBTR2=OFF, EBTR3=OFF, EBTRB=OFF #ENDCONFIG define OSC 64 OSCCON = $70 ; 64Mhz OSCTUNE.6 = 1 ; Enable 4x PLL while ! osccon2.7 :WEND ; to make sure the pll has stabilised before you run any other code TRISB = %10111111 TRISC = %10111111 ansela=0 anselb=0 anselc=0 DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1 DEFINE HSER_CLROERR 1 ' Clear overflow automatically DEFINE HSER_SPBRG 138 ' 115200 Baud @ 64MHz, -0.08% SPBRGH = 0 BAUDCON.3 = 1 ' Enable 16 bit baudrate generator DEFINE HSER2_RCSTA 90h ' Enable serial port & continuous receive DEFINE HSER2_TXSTA 24h ' Enable transmit, BRGH = 1 DEFINE HSER2_CLROERR 1 ' Clear overflow automatically DEFINE HSER2_SPBRG 160 ' 38400 Baud @ 64MHz, -0.08% SPBRGH2 = 1 BAUDCON2.3 = 1 ' Enable 16 bit baudrate generator DATAIN var byte[5] ;key pkt pword var byte[4] ;holds password pbuff var byte[4] ;ringbuffer must be pow of 2 buff var byte[4] ;buffer to test password input pbuffinx var byte ;ringbuffer index chksum var byte ;the key pkt checksum if used key var byte ;the key just read in i var byte ;num1 data "070D0000313B" ; this is number 1 ;num2 data "070D00003238" ; this is number 2 ;num3 data "070D00003339" ; this is number 3 ;num4 data "070D0000343E" ; this is number 4 ;num5 data "070D0000353F" ; this is number 5 ;num6 Data "070D0000363C" ; this is number 6 ;num7 Data "070D0000373D" ; this is number 7 ;num8 Data "070D00003832" ; this is number 8 ;num9 data "070D00003933" ; this is number 9 ;num10 data "070D00002A20" ; this is number * ;num11 data "070D0000303A" ; this is number 0 ;num12 data "070D00000802" ; this is go pause 1000 HSERout2 ["ready"] ;debug arraywrite pword ,["*478"] ;set password pbuffinx = 0 Start: gosub readkey if key != 8 then ;not go key HSERout2 [key] ;debug pbuff[pbuffinx] = key ;add key to ringbuffer pbuffinx = (pbuffinx+1)&3 ;inc ringbuffer index else ;is go key for i = 0 to 3 ;read ringbuffer into buffer buff[i] = pbuff[(pbuffinx+i)&3] next HSERout2 [13,10,str buff\4,13,10];debug ARRAYREAD buff,4,fail,[WAITSTR pword\4] ;test password goto unlocked endif goto start unlocked: HSERout2 ["unlocked"] ;debug pbuffinx = 0 ;may not be needed goto start fail: pbuffinx = 0 ;may not be needed HSERout2 ["failed"] ;debug goto start readkey: ;read key pkt HSERIN [WAIT($07), str datain\5] ' chksum=7 ;chksum untested proteus vterminal won't allow null chr to be sent ' for i=0 to 4 ' chksum = chksum ^ datain[i] ' next ' if chksum then goto readkey ;dud read key = datain[3] return
Warning I'm not a teacher
Hi Richard,
thanks so much for your help and time. I need to read carefully your code and understand it.
right now i'm testing the circuit.
The unused pins either i will pull them up with a resistors, or i will make ports outputs and set them to low.
I see in your code you have made those unused pins as inputs.
my answer is the same as you asked last time-The unused pins either i will pull them up with a resistors, or i will make ports outputs and set them to low.
I see in your code you have made those unused pins as inputs.
if your program if affected by unused pins then your program is defective.
when bread boarding unused pins left as inputs are less likely to be damaged by
inadvertent connection.
chip current consumption can be reduced by not having floating pins (by a few micro amps).
enabling weak pull on unused inputs will stop them floating but consumes a few micro watts.
setting unused pins low and as output consumes the minimal possible micro watts.
the same can be achieved leaving them as input but physically grounding them.
if the project is to be battery driven i will worry about unused pins in the final production version
otherwise it is of no consequence.
Last edited by richard; - 16th August 2020 at 00:25.
Warning I'm not a teacher
Richard, thanks once again.
The final version will be under a 12V power supply. So there is no problem thinking about power consumption.
Physically the final version might have resistors to unused pins pulled to +5V.
At the moment i'm testing the circuit on breadboard for 3 days and there is no problem at all.
P.S.
So if you use for example the "if"/Henrik.
EDIT: One more thing: You're clearly reading PORTB which must mean you're using those five low bits as inputs, yet, at the top of the program you have TRISB = %00000000 which makes all of PORTB outputs...
that mean that we make the port as input? If that so, then what is the way to read the status of the port...."high" or "low" or even the value of the port?Code:if LATB.0 = 0
In the mean time im reading the manual.
Bookmarks