PDA

View Full Version : Serial Communication with PC code



mike12345
- 23rd May 2006, 22:08
Please forgive me, I am only a beginner...

I want my PIC to send the constant 'name' over the serial port to my computer when a button is pressed. This is my first time with PICBasic so I may be completely wrong but what I want to do is put the PIC to sleep until and interrupt occurs. When there is an interrupt on RB0, the PIC will wake up and send data along the serial port. Any coding help is greatly appreciated. The code is below...

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

program wdev1

const name = 0001

PORTB.0 = 1 'port RBO as input?

sub procedure interrupt 'interrupt procedure (I think)
if INTCON.INTF = 1 then 'check port RBO

USART_Write(name) 'send serial data (name)

Delay_ms(1000) 'delay 1 second

USART_Write(name) 'send second packet

INTCON.INTF = 0 'set RBO to 0

end if

end sub

main:

INTCON = %10010000 'allow interrupts?

USART_Init(2400) 'set baud rate to 2400

asm 'include assembler code

SLEEP 'sleep until interrupt method is called to preserve power

end asm

end.

-----------------------------------------------
Thanks a million!!

mister_e
- 24th May 2006, 01:21
what PIC compiler do you use... i feel that it's not the MELABS PICBasic :(

mike12345
- 24th May 2006, 02:15
I use XCSB LITE from http://www.xcprod.com/titan/XCSB/... is that any good? This is my first program ever on a PIC. Thanks.

mister_e
- 24th May 2006, 03:04
i can't tell if it's good or not 'cause i don't use it. I only use Melabs PICBASIC Pro and Hi-Tech C compilers.

BUT as i read from your link, they have their own forum. Link bellow
http://www.xcsb.com/cgi-bin/yabb/YaBB.cgi

Good luck!

mike12345
- 24th May 2006, 03:16
Thank you for the link...I had not noticed that before.