PDA

View Full Version : Auto Downloads



TONIGALEA
- 23rd September 2004, 17:13
Hello Everyone
i am making a data logger which stores data to a serial eeprom.
i want to know how i can make my data logger go into download mode when i plug the 9 Way D type cable to a PC
i am using Hardware uart on the PIC16f877 and i can use Hserout to download the data stored to my eeprom by pressing a push button which then jumps to my download sub.
The problem is that the unit the logger is going into would not have a push button the user should be able to go into download mode when the pc cable is plugged in.
How can i do this?
Also because i would also be using a bootloader is there a way of doing this with just 3 wires TX,RX & Gnd/


Toni

Bruce
- 23rd September 2004, 18:39
If you have control over the PC application, then have it ping the data logger (sending an occasional byte) until the logger responds.

On the PIC side, simply test RCIF on occasion to determine if the PC has been connected, the ping byte has been received, and the RCREG holds something.

The USART can handle all this in the background, and your main code can do whatever until the PC is connected.




Y VAR byte ' Inbound data recovered from RCREG
RCIF VAR PIR1.5 ' USART received character interrupt flag bit
CREN VAR RCSTA.4 ' USART continuous receive enable bit
OERR VAR RCSTA.1 ' USART over-run bit

INTCON = 0 ' Disable interrupts (just using flags)
ADCON1 = 7 ' A/D off

TRISB.0 = 0 ' Set RB0 to output
PORTB.0 = 0 ' LED off (indicates data was in RCREG)

Main:
IF RCIF THEN Have_Data ' If RCIF=1 there's data in RCREG
HIGH 1 ' so jump to Have_Data and send your EEPROM
PAUSE 1000 ' contents
LOW 1
PAUSE 1000 ' Long pauses show how RCREG receives data
GOTO Main ' in the background

Have_Data: ' Send your EEPROM data here
PORTB.0 = PORTB.0 ^ 1 ' Toggle RB0 to indicate data rcvd
WHILE RCIF ' Empty RCREG by reading it
Y = RCREG
WEND
' If OERR = 1 then the over-run bit is set and we need to clear it
' to re-enable receive. If not, then carry on
IF !OERR THEN Main ' If no over-run condition, return to Main
CREN = 0 ' Over-run condition. Disable receive
CREN = 1 ' Re-enable & clear OERR flag
GOTO Main

TONIGALEA
- 24th September 2004, 13:14
Bruce
Thank you very much for the time and effort you put into answering my questions.
i tried the example you gave and it worked perfectly.
the program goes to the Have_Data: sub when i sent any byte from the PC.
Excellent !!

BTW what does this line mean HIGH 1


Toni

Bruce
- 24th September 2004, 13:29
Hi Toni,

You're welcome.

< BTW what does this line mean HIGH 1

HIGH & LOW are PBP commands to make the specified pin high or low. Both are explained in your PBP manual.

TONIGALEA
- 24th September 2004, 16:49
I do know that bruce
what i was really asking is if High can be used in that way without the port pin
example High portb.1 takes portb.1 to 5v
High 1 what is the port pin ?

Toni

Bruce
- 24th September 2004, 17:33
Hi Tony,

When you use the HIGH or LOW commands with numeric pin specifiers like 0,1,2,3 etc,, it starts from RB0, and continues on to RC7. With 0 being RB0 and 15 being RC7.

Of course you can still use HIGH PORTB.0 too, but if you use the HIGH or LOW commands for port pins other than RB0 to RC7, then you can't use numeric pin specifiers.

You would specify port pins like this -

HIGH PORTA.0
HIGH PORTA.1
HIGH PORTD.1
etc,,.

If you specify an illegal bit # with one of these commands such as HIGH 16, PBP returns the error "illegal bit number".

Using numeric pin specifiers like HIGH 0, LOW 0 rather than HIGH PORTB.0, LOW PORTB.0 comes in handy.

Example;


X VAR BYTE

MAIN: ' LED Light chaser on RB0 to RC7
FOR X = 0 TO 15 ' Light LED's on RB0 to RC7
HIGH X
PAUSE 50
NEXT X

FOR X = 15 TO 0 STEP-1 ' Turn them back off
LOW X
PAUSE 50
NEXT X

GOTO MAIN

Santana
- 25th September 2004, 14:13
Hi Bruce
i have learn't something from your reply to Toni
i didn't know you could use numeric pin specifiers like 0,1,2,3 etc
Thanks for the clearification
Also with your auto download example that was great the only point i didn't like is that any byte sent from the pc activates to download.
Is there a way were the auto download is started by a specific
btye ?

Keep Teaching Us

Bruce
- 25th September 2004, 14:50
Just test the value received to look for a specific character.

Y = RCREG
IF Y = ? THEN

Santana
- 21st October 2004, 22:55
Hi Guys/Ladies
What is the best way to put and wake my pic to sleep
i am designing a data logger that would be battery operated
and would date stamp my readings and store to a serial eeprom.
Some people might want to take readings only once an hour
and the reading only take a minute max .
How can put the pic 18F452 to sleep then wake it up just before the user reading time.
Would i need to use a RTC that can trigger an interupt on RB0 ?
Just a few pointers in the right direction

TONIGALEA
- 16th November 2004, 10:58
Hi Bruce and others
Sorry i have to come back to this topic again
On my data logger i simply test RCIF on occasion to determine if the PC has been connected, this works ok
But the problem is that the pic is aspleep 99% of the time and it dosen't responds to the ping when in sleep mode.
i was going to use a link jumper to link a pin to gnd when the user needs to make configurations so that the pic test to see if this pin is 0v than jump over the sleep part of my code but the end user want everything done from the PC end
is there a way i can do even if i have to use more than 3 wires for my serial connection


Regards
Toni

Melanie
- 16th November 2004, 12:47
Why not simply cross-connect your SERIN/HSERIN pin additionally with say RB0 (or any of RB1-4), and when there's any serial activity it'll wake the PIC from sleep. Actually, doesn't the USART have that abaility too...

TONIGALEA
- 16th November 2004, 13:09
I didn't think that the Uart could do this when in sleep mode

Melanie
- 16th November 2004, 19:21
Just double-checked, it does, but only in sync-slave mode... OK, so back to the idea of cross connecting your USART pin with one of the PortB pins to wake on status change. There's nothing in the rules that says you can't connect your input to more than one PIC pin.