Yup, you are heading South now.
I'm intrigued, what you working on then mackrackitWhile I am on my way North with the gizmo I am playing with.
Yup, you are heading South now.
I'm intrigued, what you working on then mackrackitWhile I am on my way North with the gizmo I am playing with.
I got the bright idea that would figure this one out.
http://www.picbasic.co.uk/forum/showthread.php?t=12948
Dave
Always wear safety glasses while programming.
Hi mackrackit,
I've got something that 'works'
If I just load the program into the 16F684 and leave it running, every 10 secs PORTA.1 LED blinks as per the Timeout setting. I've given it a 10 secs delay because it takes about 4 secs to input two numbers into my clunky old keyboard.Code:ANSEL = %00000000 'Disable analog select so ports work as digital i/o. CMCON0 = %00000111 'Disable analog comparators. TRISA = %00000000 'Set PORTA as OUTPUT. PORTA = %00000000 'Set PORTA pins all low. TRISC = %00000000 'Set PORTC as OUTPUT. PORTC = %00000000 'Set PORTC pins all low. DEFINE OSC 4 NUM1 VAR BYTE NUM2 VAR BYTE TOTAL VAR BYTE Timeout con 10000 MAIN: PAUSE 250 SERIN2 PORTC.5, 16780,Timeout,Data_Not_Sent,[DEC NUM1, DEC2 NUM2] PAUSE 6000 HIGH PORTA.5 PAUSE 1000 LOW PORTA.5 LET TOTAL = NUM1 + NUM2 PAUSE 250 SEROUT2 PORTC.3, 16780, [DEC TOTAL, 10] pause 250 DATA_Not_sent: High PORTA.1 PAUSE 75 LOW PORTA.1 GOTO MAIN
You might be wondering why there's a six second delay after the NUM's are inputted, it's so I can visually see via the LED PORTA.5 that it has arrived (if that makes sense).
What do you think.
Dave
Last edited by LEDave; - 16th April 2010 at 13:45.
That's great Dave, you're making a lot of progress!
What happens if you input 200 and 300 for num1 and num2 ? Why?
Next challenge, if mackrackit don't mind:
Make it so you actually input the complete equation, not only the two numbers. In other words 200+300 or 20-30 or 5*12 or....
/Henrik.
Looking good Dave!!!
Now you have Henrik's challenge.
Sounds like a good next step to me.
Henrik, I do not mind at all, the more teachers the better.
Dave
Always wear safety glasses while programming.
Thanks to mackrackit and yourself I amThat's great Dave, you're making a lot of progress!When you think that in February I couldn't turn an LED on or even create a HEX file....!
Right then:
Well the answer / output would be 230. Reason 200 is fine (BYTE = 255) the 300 which due to a mistake by me I set as D2 (DECIMAL2) in the program only takes the first two digits 30 so 200+30=230. How does that sound?What happens if you input 200 and 300 for num1 and num2 ? Why?
Well the for first part 200+300 I'd have to set TOTAL VARIABLE BYTE to TOTAL VARIABLE WORD for the number 300 (that's assuming you can add a BYTE to a WORD.....Mmm, something makes me think this isn't going to be that straight forward......!Make it so you actually input the complete equation, not only the two numbers. In other words 200+300 or 20-30 or 5*12 or....
Last edited by LEDave; - 16th April 2010 at 16:59.
Hi Dave,
You are correct, in your case it would be 230. (I missed that DEC2 you had in there).
What I was really going for was the fact that you have all three variables, Num1, Num2 and Total all declared as Bytes. So 200 in Num1, that's fine. But 300 in Num2 won't work as it will overflow and will actually result in the value 44 in Num2 the Total would be 244. Same thing if you'd do 200+200, Num1 is fine and so is Num2 but 400 won't fit in Total... You seem to have that under control though!
For the next exercise, why not make the PIC ask three questions like:
Num1: (You input whatever)
Operator: (You input +, - / or *)
Num2: (You input whatever)
And then present the result. That should make it a little easier to sort out - I think.
/Henrik.
Bookmarks