PIC compiling problem

Thread Starter

electronic_noob

Joined Jan 15, 2010
42
:Dhey guys, I have a problem here... I got this code which I have compiled I already checked it in proteus and the program seems to be working fine, no error..., then I compiled it using icprog. Everything was fine, no error on writing the code (I perform first the erase all instruction) then I configured it. The program was compiled on the PIC. At first the PIC worked perfectly fine, (by the way my PIC accepts ascii codes generated by my PC's serial port) but after some trials, the PIC stopped functioning. The protocol of the PIC is this, the PIC would wait about 30 instructions(well that would be about 30 ascii characters, each has a starting bit which is the ascii code of 'A') after receiving the instruction, the PIC would then set the LEDs on it's outputs high depending on the input character so there is 30 ascii charactes, meaning there would be 30 combinations at 1 second interval.. Is it possible that the program in my PIC was altered during programming, I use EEPROM, using PICBASICPRO.

what is the possible mistake that I had made??
why did the PIC reacted that way, I had checked the connections everything is connected on where they should be connected...and also Im transmitting data through serial port "wirelessly".
 

mik3

Joined Feb 4, 2008
4,843
With some PICs the program can be changed by the PIC itself but it is an advanced topic so I don't think you progammed that.

What do you mean you transmit data wirelessly?

Maybe the serial port is not working anymore.
 

Thread Starter

electronic_noob

Joined Jan 15, 2010
42
With some PICs the program can be changed by the PIC itself but it is an advanced topic so I don't think you progammed that.

What do you mean you transmit data wirelessly?

Maybe the serial port is not working anymore.
the serial port is working properly, I've transmitted some commands and the pic responded to it, but later the pic stopped working...I really dont know what happened..., I use EEPROM on pic, to store about 30commands then execute those commands after receiving the last command(the 30th),...do i need to include a command to erase the EEPROM to be able to receive a new 30command batch, is there a command for erasing EEPROM?

because maybe that is the problem

the serial port is working properly and my two transceiver also works properly, because both has a led that lights when receiving and transmitting data,(in my case the moment I type an ascii character)
 

Thread Starter

electronic_noob

Joined Jan 15, 2010
42
After reset the program does work again, or everything is dead after your first trail? Did you try to reprogram the chip?

You didn't mention which pic type you are using.

Remember that posting your code and the wiring diagram of the project is the best way to have the problem solved quickly.

Alberto
Im using 16f628A this is my code:

"
TRISB = %00000000
'TRISA= %10000011
'DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive

@ DEVICE pic16F628A,INTOSC_OSC_NOCLKOUT
@ DEVICE pic16F628A,WDT_OFF
@ DEVICE pic16F628A,CPD_OFF
@ DEVICE PIC16F628A,PROTECT_OFF
@ DEVICE PIC16F628A,BOD_OFF
@ DEVICE PIC16F628A,LVP_OFF
@ DEVICE PIC16F628A,MCLR_OFF




CMCON=7
B0 VAR BYTE
CNT VAR BYTE
i var byte
marcus var byte
q var byte


MAIN:
PORTB=0
i=0
Q=0
WHILE i<6
SERIN PORTA.0,2,["A"],B0
WRITE 1*i,B0
i=i+1
wend
LOOP1:
PORTB=0
while q<6
read 1*q,marcus
Q=Q+1

IF marcus.0=1 THEN
HIGH PORTB.3
ENDIF
IF marcus.1=1 THEN
HIGH PORTB.4
ENDIF
IF marcus.2=1 THEN
HIGH PORTB.5
ENDIF
IF marcus.3=1 THEN
HIGH PORTB.6
ENDIF
PAUSE 1000
GOTO LOOP1
WEND
GOTO MAIN

end
"

I've included the circuit diagram(made in Proteus) Well this is just half of what I intend to do, Is there something wrong with my code....my knowledge on picbasic is very little since Im just studying it for about 3 days, I have a little knowledge on the programming especially about the headers, (the "include", and "defines" and those @)

and the EEPROM.

I need your help really, thanks a lot
 

Attachments

Thread Starter

electronic_noob

Joined Jan 15, 2010
42
Question: are using picbasicPro?

There are some issue with your code:

1) You are using the internal oscillator without setting the register for the required frequency.

2) you are using portA.0 for serial input and you have commented out the trisA command. It should be TRISA = %00000001

3) I don't see the reason to write the eeprom and then read it back. Use an array of bytes for this purpose.
Remember that eeprom has a 100K write cycle than they don't work anymore, so it is not reccomandable to write to them in loops.
If necessary to hold the data this should be done at the end (before switch off )

4) If you use picbasic then you have to INCLUDE "Modedefs.bas" for the correct serial setting (true 9600 bauds)

5) Don't see the reason for the while/wend loop.

6) Your schematic doesn't show any wiring

If you need I will arrange your code, if you tell me what you want to achieve and complete the wiring diagram.

Alberto

Im using picbasic pro

1. how could I set the register for the required frequency? is there any default frequency, because in circuit simulation my circuit worked. I think the default frequency is 4Mhz

2. About commenting that trisA, It just mean I excluded it....somehow the circuit still works, Ive tested it and it works

3. Well the EEPROM thing is used that way because of the type of program I want it to do. Well, it goes lke this Ill be controlling 4 electric appliances its like a schedule, in a definite time there would be a specific combination on which of the appliance should be turn OFF or ON using a computer(with two transceiver) the reason that I used loops is because I want the pic to first get a set of commands(well a schedule) then after getting it implement it, thats why I perform READ so lets say in one whole day I only need to send the data to the pic one time, and the whole schedule or combinations of the appliances would be set for one day.

4. about the INCLUDE "Modedefs.bas" I search about that and it seems I neeed to include it only if Im performing "SEROUT" commands. (Well, I'll be using serout any way thanks for mentioning that header file)

5. Well the while /wend loop is use as a filter/counter(I dont know if I had used the correct term), through the while/wend command the PIC would wait for the maximum assign number of commands to be stored on its EEPROM before it would implement it, well I know you would understand it by now because I have explained my protocol a while ago

6. It does show wiring, it's proteus its the sae as putting resistors after the specified portpins in series with LED. those "i>" "<i" symbols on my circuit are simply input /output terminals. Its hard to explain but I know you would have th idea why I use LED.

Lastly ,I would be in deep gratitude if you could arrange me some codes but is it too much?

but I would be thankful, very thankful
 

Thread Starter

electronic_noob

Joined Jan 15, 2010
42
I read the datasheet for 16F628 and actually you were correct, this chip has only one fixed frequency for the internal oscillator (4 MHz). So there is no OSCON register to set.

The code below should work, I did compile it without your @Device setting because my compiler works differently. Tray it and see.

Alberto

Rich (BB code):
@ DEVICE pic16F628A,INTOSC_OSC_NOCLKOUT
@ DEVICE pic16F628A,WDT_OFF
@ DEVICE pic16F628A,CPD_OFF
@ DEVICE PIC16F628A,PROTECT_OFF
@ DEVICE PIC16F628A,BOD_OFF
@ DEVICE PIC16F628A,LVP_OFF
@ DEVICE PIC16F628A,MCLR_OFF


INCLUDE "Modedefs.bas"

CMCON=7

DEFINE OSC 4

PortB = 0
PortA = 0

TRISB = %00000000
TRISA= %10000011




False       con 0
True        con 1

B0          VAR BYTE
CNT         VAR BYTE
i           var byte
marcus      var byte
q           var byte


MAIN:

    i = 0
    Q = 0

WHILE i < 6
SERIN PORTA.0,2,["A"],B0
WRITE 1*i,B0
i = i + 1
wend

LOOP1:
while q < 6
read 1*q,marcus
Q = Q + 1

IF marcus.0 = true THEN
HIGH PORTB.3
else
low PORTB.3
ENDIF

IF marcus.1 = True THEN
HIGH PORTB.4
else
low PortB.4
ENDIF

IF marcus.2 = True THEN
HIGH PORTB.5
else
Low PortB.5
ENDIF

IF marcus.3 = true THEN
HIGH PORTB.6
else
low PortB.6
ENDIF

PAUSE 1000
GOTO LOOP1
WEND
GOTO MAIN

end

thanks for the code , Im planning to include a serout command, but when I tried it, the program does compile and it does what I want to do but it does not send something back...I program it that when it receive the commands it would send back a message "HELLO", but it does send anything. The connections are correct I figure maybe there is still something I need to configure in the hyperterminal, Do I need to include pause between serin and serout? Well the "HELLO" thing is only to test if could really send something back. By the way the circuit ran smoothly but after the last input the last LED combination stayed litted, wherein it should be turned off, but I fixed the problem by including the command 'portb=0' after the last wend command.

How many hyperterminal should I open?
Do I need two separate hyperterminals one for receive and one for transmit
I called the only one serial port...com1
 
Last edited:

Thread Starter

electronic_noob

Joined Jan 15, 2010
42
You need to open only one hyperterminal (two will conflict if using the same serial port).

How did you connect the pic to the PC? Via a level translator (max232) or directly with a resistor.

Can you show both the connection for Tx and Rx between the pic and PC?

The reason is that the level translator will invert the signal, so you will use the "TRUE STATE" mode 2, otherwise you shoul use the "INVERTED STATE" mode 6 for both Tx and Rx.

Alberto
I use max232, before the transceiver the PIC's circuitry is place with the other transceiver. I checked the datasheet of both the transceivers, the max232 all seem to be connected correct, also with the PC's serial port. My only problem is I can't perform SEROUT, but I can perform serin. I really don't know where would the SEROUT 'output' would be displayed,Will it be displayed on the same hyperterminal I've been transmitting with.

what do you mean by this:
"The reason is that the level translator will invert the signal, so you will use the "TRUE STATE" mode 2, otherwise you shoul use the "INVERTED STATE" mode 6 for both Tx and Rx".

mode 2 meaning the baud? that is 9600
and mode which is inverted 9600

so in SERIN I need to use mode2 but as I perform serout I need to use mode 6 am I correct
or is it mode 6 both ways
 
Last edited:

Thread Starter

electronic_noob

Joined Jan 15, 2010
42
The document you have attached is for an assembled board, I was talking about the 16 pins chip max232!

I cann't say much about this assembled rs232 level translator appart that you have to remove the jumper from JP3 and that you have to make sure that all the wiring are correct as per the datasheet you have posted.

If after deep check you come to the conclusion that wiring are all correct and reliable then the only answer is that Tx line is faulty and you have to change the board. (I wish not)

In such an unluky event take into consideration to buy the maxim max232. (will cost you few cents)

Alberto
The datasheet said to remove jumper from JP3, but when I remove it I could not transmit any signal but If I put it back again it does transmit, does that mean that my assembled rs232 level translator is faulty
 

Thread Starter

electronic_noob

Joined Jan 15, 2010
42
there seem to be a problem in my connection I look at the data sheet and there are two pins in PORTB that made specifically for TX and RX, that maybe is the problem...I'll try it out and see
 

Markd77

Joined Sep 7, 2009
2,806
I think this is what you are looking for - in table 5.3 of 16F628 datasheet:

RB1/RX/DT RB1 TTL CMOS Bi-directional I/O port. Can be software programmed for
internal weak pull-up.
RX ST — USART Receive Pin
DT ST CMOS Synchronous data I/O


RB2/TX/CK RB2 TTL CMOS Bi-directional I/O port
TX — CMOS USART Transmit Pin
CK ST CMOS Synchronous Clock I/O. Can be software programmed
for internal weak pull-up.
 

Thread Starter

electronic_noob

Joined Jan 15, 2010
42
well I decided, to use serin instead...I'm finding it hard to use hserin, I seem to encounter some unfamiliar errors. I cant perform serout on my circuit wherein i just concluded that my max232 is faulty. My project is almost into completion I understand that if one find it hard to do in the program theres always something you could do about it in the hardware(is this the right term?) Well thanks especially to Alberto, you've been patient. Sorry for some silly questions.

THANKS!!!!!!!!!
 
Top