PDA

View Full Version : Sending menu to PC from PIC16F876A



joseph Degorio
- 11th November 2007, 09:10
Greetings experts!
I'm new to PBP and just bought a LABX2. I'm trying to run a simple program that will display menu from the chip to the PC. Kindly check the codes below, nothing shows to the serial comm window after compiling.



include "modedefs.bas" 'include serout defines
RX var byte ' Receive byte
LED var bit ' LED status bit
Init:
TRISB = %00000000
TRISC = %01000000 'PortC.7 RX
'input
PORTB = %00000000 'Initialize PortB to all zeros and LED
'to off
LED = 0 'Initialize LED flag to 0
' ——-[ Main Code ]———————————————————————————-

Menu:
Pause 500

serout PORTC.6, 0, ["menu", 10, 13] 'Display menu
'on PC screen
serout PORTC.6, 0, [#1, ") ", "send hello", 10, 13]
serout PORTC.6, 0, [#2, ") ", "send goodbye", 10, 13]
serout PORTC.6, 0, [#3, ") ", "toggle LED", 10, 13]
Receive:
' ***** [Receive the menu selection from PC] ***************
serin PORTC.7, 0, RX 'Receive menu
'number
RX = RX - $30 'Convert ASCII
'number to decimal
If RX > 3 then Error ' Test for
'good value
Branch RX, [zero, one, two, three] 'redirect to menu
'selection code
Error:
serout PORTC.6, 0, ["error", 10, 13, "Try again", 10, 13]
goto menu
Zero:
'***** [ Code for zero value ] *****************************
goto menu 'Return to menu, zero is not a
'valid selection
One:
'***** [Code for selection 1] *************************
serout PORTC.6, 0, ["Hello", 10, 13] 'Send "Hello" back
'to PC
goto menu 'Return to main menu
'routine
Two:
'***** [Code for selection 2] *************************
serout PORTC.6, 0, ["Goodbye", 10, 13] 'Send "Goodbye" to
'PC
goto menu 'Return to Menu routine
Three:
'***** [Code for selection 3] **********************
if LED = 1 then LEDoff 'If LED bit =1 then goto off
portb.0 = 1 'Turn LED on
led = 1 'Set LED bit to 1
serout PORTC.6, 0, ["LED ON", 10, 13] 'Send LED status to
'PC
goto menu 'Return to main menu
LEDOff:
portb.0 = 0 'Turn LED off
led = 0 'Clear LED bit to 0
serout PORTC.6, 0, ["LED OFF", 10, 13] 'Send LED status to
'PC
goto menu 'Return to main menu
Goto menu


Thanks,
joe

mister_e
- 11th November 2007, 09:58
Unless your configuration fuse setting is wrong or your you have a hardware problem, it has to work AS-IS... at least your PC have to receive your first text strings.

What are you using to receive your strings? The painful & useless Hyperterminal or MicroCode Studio?

joseph Degorio
- 12th November 2007, 08:03
Hi Steve,
I just found out that if I remove the line with this command "serin PORTC.7, 0, RX 'Receive menu" the menu displays to the serial comm window. According to Labx2 schematic RX is PortC7. Please guide me...


Thanks in advance,
Joe