Exactly,even stranger though!Kind of like science fiction.
Here's tonight's effort, it works up to DEC255 then ouputs a zero for 256 etc, which is larger than a BYTE I'm thinking.
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 MYVAR VAR BYTE MAIN: PAUSE 250 SERIN2 PORTC.5, 16780, [DEC MYVAR] 'MODE 16780 = 2400 BAUD INVERTED IF MYVAR = MYVAR THEN HIGH PORTA.5 'LET'S YOU INPUT ANY NUMBER. PAUSE 5000 low PORTA.5 pause 250 SEROUT2 PORTC.3, 16780, [HEX MYVAR, 10, 13] 'OUTPUT IN HEX 'MYVAR' 10=L_FEED 13=C_RETURN pause 5000 GOTO MAIN
Last edited by LEDave; - 13th April 2010 at 21:02.
From the second part of the brief:
Hmm, a little stumped here. To my mind (after a lot of reading but obviously not enough!) when the first BYTE (number) arrives I need to send it to a memory location where it won't be overwritten when the second BYTE arrives.Then add the two together.Could even send a couple of numbers and have an operation done on them and the results sent back to the PC.
The only thing I've found so far that has a seperate address element is this (I think):
I'm thinking: MYVAR VAR BYTE [1] which is two elements 0,1. then somehow add element 0 to element1.Code:Label VAR Size[Number of elements]
Warm or way off?
Dave
Now I'm thinking:
Might be used to output a block of data....Mmm..Code:Label VAR Size[Number of elements]
A little more research me thinks.
Dave
Yup, remember when counting not to start at 1 like we were taught in school.it works up to DEC255 then ouputs a zero for 256 etc, which is larger than a BYTE I'm thinking.
Always start at the origin... ZERO
I was thinking along the lines of something like this for nowHmm, a little stumped here. To my mind (after a lot of reading but obviously not enough!) when the first BYTE (number) arrives I need to send it to a memory location where it won't be overwritten when the second BYTE arrives.Then add the two together.
The only thing I've found so far that has a seperate address element is this (I think):
I was saving ARRAYs for a little latterCode:NUM1 VAR BYTE NUM2 VAR BYTE
But if you want to read ahead...I'm thinking: MYVAR VAR BYTE [1] which is two elements 0,1. then somehow add element 0 to element1.
http://www.picbasic.co.uk/forum/showthread.php?t=544
Dave
Always wear safety glasses while programming.
Hi mackrackit
I'm with you, reading ahead is ok but learn to walk then run (or crawl then walk in my case).But if you want to read ahead...
Just out of interest would the ARRAY idea have worked?
This code is just an idea, is it on the right lines?
Code:SERIN2 PORTC.5, 16780, [DEC NUM1] 'MODE 16780 = 2400 BAUD INVERTED SERIN2 PORTC.5, 16780, [DEC NUM2] 'MODE 16780 = 2400 BAUD INVERTED LET TOTAL = NUM1 + NUM2 SEROUT2 PORTC.3 TOTAL
An array can be made to work and so could your code as it is written, but...
One of the things you need to consider is, how is the data coming into the MCU?
123
1,2,3
12,3
12M3
...........
The code on the MCU needs to know what to expect or it is not going to know what to do with the data.
That is where arrays come in handy, but then you need to figure out what and where the data you want to use is located in the array.
I know, not a direct answer
Reread the section of the manual SERIN2 and the WAIT thing. Also find out what DEC2 or DEC3 does.
Dave
Always wear safety glasses while programming.
Bookmarks