Hi mackrackit,
I've been working really hard on this. I've taken your idea of:
Can you setup a LCD or have the value of x sent to a terminal?
And done this:
What I've done is change the original code to measure the time the LED is on rather than measure the time the program was 'PAUSED' because to my mind you can only use 'PULSIN' on a active pin. I've then tried to output that 'PULSIN' number using 'SEROUT2' to the Serial communicator.
It nearly works I think, what it does is output a series of zeros, instead of the time in micro_secs. I suspect I've made an error here:
Code:
SEROUT2 PORTC.3, 16780, [DEC Z, 10 ,13] 'The measured RANDOM time sent to S/Communicator
I think it could be the Decimal value of Z that's causing the problem (I hope) being as it should be measuring in blocks of Micro_secs.
Here's the program, I feel I'm close, but am I?. If you could look the program over and give me a pointer that would be really appreciated. The chip is a 16F684.
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
X VAR WORD 'Number between 1 & 65535
Y var WORD 'Scaled down value of X
Z VAR BYTE 'The PAUSED value of Y in 10us Increments
main:
RANDOM X 'Random number between 1 & 65535
LET Y = (x /14) 'Scaled down value of X
HIGH PORTA.2 'LED PORTA.2 lights up
PAUSE Y 'LED on for time period of RAN_X_OVER_14
PULSIN PORTA.2,1,Z 'The paused RANDOM time period stored in VAR Z
SEROUT2 PORTC.3, 16780, [DEC Z, 10 ,13] 'The measured RANDOM time sent to S/Communicator
'in 10us incremets
low PORTA.2 'LED off
GOTO MAIN: 'Do it all again
Dave
Bookmarks