Hi.
I try a small project that send command via PC serial port to a PIC12F625 connected without MAX232. I use some example from Serial Port Expander.
Here I try to light a LED connected on pin GP1 of PIC12F625.
The code is in PBP.
I used Visual Basic 6 to build the windows executable.
I used Proteus 7.2 to made the schematic and simulating the circuit; simulation works fine, I put a virtual terminal on pin 3 of serial port and type „a01” to light the led and „a00” to shut the led.
But in practice my project doesn’t work; I have a signal on GPIO.0 port pin of 12F625 but nothing on GPIO.1.
Do you have any ideea?
Thank you.
Code:Visual Basic Option Explicit Private Sub CommandOFF_Click() Dim sir As String DoEvents sir = "a" & "0" & "0" MSComm1.Output = sir Shape1.FillColor = vbRed End Sub Private Sub CommandON_Click() Dim sir As String DoEvents sir = "a" & "0" & "1" MSComm1.Output = sir Shape1.FillColor = vbGreen End Sub Private Sub Form_Load() MSComm1.CommPort = 1 MSComm1.Settings = "2400,n,8,2" MSComm1.InputLen = 0 MSComm1.RThreshold = 1 MSComm1.PortOpen = True If MSComm1.PortOpen = False Then Debug.Print "Port closed" Else Debug.Print "Port opened" End If End SubCode:PICBasic Code ' PIC12F675 ' Pic Basic Pro Compiler 2.45, (c) 1998, 2004 microEngineering Labs, Inc. ' Assembler used is PM.EXE, provided with microEngineering Labs PICBasic Compiler ' ' This program flashes an LED connected to port GP1. ' ************************************************* ************ ' REMOTE RX ' ************************************************************** ' Pic Basic Pro Compiler 2.45A1, (c) microEngineering Labs, Inc. ' Assembler used is PM.EXE, provided with microEngineering Labs PICBasic Compiler define OSC 4 INCLUDE "modedefs.bas" @ DEVICE PIC12F675 ANSEL = 000000 'set all pin 0 = Digital I/O; ADCON0.7 = 1 ' Right justify result CMCON = 7 ' Analog comparators off @ DEVICE PIC12F675, INTRC_OSC; Use internal oscilator @ DEVICE PIC12F675, WDT_OFF ;WATCHDOG @ DEVICE PIC12F675, PWRT_OFF ;POWER ON TIMER @ DEVICE PIC12F675, BOD_OFF ;BROWNOUT RESET @ DEVICE PIC12F675, MCLR_OFF trisio = 100001 INTCON=0 'interrupts off CMCON=7 'all digital for low power use 'CMCON disables the comparator LedNr var byte stat var byte LedOut VAR GPIO.1 'GP1 Led output SerialIn VAR GPIO.0 'serial input pin 'start ' Set Debug pin port DEFINE DEBUG_REG GPIO ' Set Debug pin bit DEFINE DEBUG_BIT 2 ' Set Debug baud rate DEFINE DEBUG_BAUD 2400 ' Set Debug mode: 0 = true, 1 = inverted DEFINE DEBUG_MODE 0 DEFINE DEBUG_PACING 1000 debug $0D,$0A debug "Start! ",$0D,$0A ledout = 0 'Shut LED loop1: ' Wait until the character "a" is received serially on SerialIn ' and put next characters into led and stat SERIN serialin,T2400,["a"],lednr,stat 'serial data in on GPIO.0 debug "Led number = ",dec LedNr," State = ",dec stat, $0D,$0A ' Led Nr = 0 IF LedNr = 48 THEN outr1 ' if request is for LED#1 then goto led#1 routine 'IF LedNr = 49 THEN outr2 ' if request is for LED#2 then goto led#2 routine GOTO loop1 outr1: IF stat = 49 THEN high1 ' If status request is I/O pin#0 logic 1 [high] pause 50 Ledout = 0 GOTO loop1 ' then make I/O pin#0 high, else make it [low] high1: pause 50 Ledout = 1 GOTO loop1 ' Make I/O pin#0 logic 1 [high] end




Bookmarks