PDA

View Full Version : Questions?



ngeronikolos
- 21st June 2005, 11:21
Hello boys and girls,
I have some questions using 16f628a 16Mhz

1) HSERIN 500,MAIN,[WAIT(A), STR SERDATA\17]
I input the A(byte) variable dit per bit and after that I want to read a stream which begins with A.Where is the wrong?Writting WAIT (A) it expects the ascii A which is something stable.

2) WHILE PORTA.3 = 1 AND PORTA.4 = 1
PAUSE 2000
If PORTA.2=1 then
I = I + 1
IF I > 8 THEN I = 1
pause 500
NICK1: WHILE PORTA.3 = 1
SerData[i] = "1"
GOSUB OUT
PAUSE 500
WEND
WHILE PORTA.4 = 1
SerData[i] = "0"
GOSUB OUT
PAUSE 500
WEND
else
GOTO NICK1
endif
WEND

I have 3 buttons.WHILE PORTA.3 and PORTA.4 are pressed together the user can make some changes.If you press THE BUTTON of PORTA.2 you can move to the one of the 8 dot leds(i=1 to 8) and pressing button PORTA.3 or PORTA.4 you can display 1 or 0.
My progaram is not working propertly but it is works.How can I do much more easier and smaller?


Thanks
Best regards
Nikos Geronikolos
HELLAS

mister_e
- 22nd June 2005, 04:42
Writting WAIT (A) it expects the ascii A which is something stable.

WAIT("A")


My progaram is not working propertly but it is works.How can I do much more easier and smaller?

CMCON=7 ' disable analog comparator

use Select Case will do the job.
MyButtons=PORTA

SELECT CASE Mybutton
Case

etc

Melanie
- 22nd June 2005, 08:21
You may find that SELECT CASE produces wonderfully readable listings for us programmers, the final compiled code it produces isn't particularly compact.

Heaps of IF statements, although not particularly neat in listings, does however produce the most compact compiled code.

Experiment one way, then the other and make your own mind up.

ngeronikolos
- 22nd June 2005, 15:28
Thanks mister_e & Melanie,

I use SELECT CASE comands and it works much better.
What about my first question?

HSERIN 500,MAIN,[WAIT(A), STR SERDATA\17]
The A is a byte.It is the start byte,an address of the stream that follows.I can change the A(byte) variable dit per bit.
What I want is while I have set the A after I want to read a stream which begins with A.
but this is not working.
HSERIN 500,MAIN,[WAIT(A), STR SERDATA\17]

If I change to WAIT("A") the pic search to read the A ASCII not the A that I have set manual.

Please help me
Thanks
NIKOS
HELLAS

mister_e
- 22nd June 2005, 16:59
If I change to WAIT("A") the pic search to read the A ASCII not the A that I have set manual.

yup but for 500mSec. What about to try only that part without any timeout??? What about to add an optional end character???

BTW, here's something to play with.


DEFINE LOADER_USED 1 ' Using Bootloader
DEFINE OSC 20 ' Using 20MHZ crystal

DEFINE HSER_RCSTA 90h ' Enable USART, continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH=1
DEFINE HSER_SPBRG 129 ' 9600 Bauds
define HSER_CLOERR 1 ' Enable automatic alear overrun error

StartByteChar VAR byte
StringOfChar VAR Byte[10]
Counter var byte
RecycleBin var byte
CLEAR ' set all variables to 0

AskUser:
hserout["Enter start byte character",13,10] '
HSERIN [StartByteChar] ' wait user choice

Start:
Hserout["Waiting for start=",startbytechar,_
" And 10 character string..........",13,10]

hserin[WAIT(Startbytechar),STR stringofchar\10] ' wait Start character
' and store 10 next
' character in StringOfChar

for counter=0 to 9 '
hserout[stringofchar[counter]] ' Display results
next '

While PIR1.5 ' Check RCIF => input buffer full??
recyclebin=RCREG ' flush all results in a don't care variable
wend '

RCSTA=0 ' simple way to clear all
RCSTA=$90 ' possible errors
pause 100 ' USART initialisation delay... value come from nowhere
hserout[13,10,rep "*"\50,13,10] ' just to make it cute on screen
goto askuser

hope this help

ngeronikolos
- 23rd June 2005, 14:44
My friend mister_e,

The start byte the user set it by pressing push buttons and you can see it to leds.
So,

A.0=LED1 ;0 OR 1
A.1=LED2
A.2=LED3
A.3=LED4
A.4=LED5
A.5=LED6
A.6=LED7
A.7=LED8

hserout[13,10,DEC A,13,10]

---------------------------------------------------

By changing the A bit per bit I can see in my terminal the corect decimal A.

HSERIN 500,MAIN,[WAIT(A), STR SERDATA\17]
When I try to send with my terminal the start bit A & the stream the pic does not recognize nothing.

IF I have set A = 01010101 MANUAL the pic expect to read the start bit A = 55 HEX?