PIC compiling problem

Discussion in 'Embedded Systems and Microcontrollers' started by electronic_noob, Jan 30, 2010.

  1. electronic_noob

    Thread Starter Member

    Jan 15, 2010
    42
    1
    :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".
     
  2. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    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.
     
  3. electronic_noob

    Thread Starter Member

    Jan 15, 2010
    42
    1
    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)
     
  4. electronic_noob

    Thread Starter Member

    Jan 15, 2010
    42
    1
    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
     
  5. electronic_noob

    Thread Starter Member

    Jan 15, 2010
    42
    1
    forgot to mention, you might be confuse
    on the wiring diagram...only B3 to B6 are connected
     
  6. electronic_noob

    Thread Starter Member

    Jan 15, 2010
    42
    1

    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
     
  7. electronic_noob

    Thread Starter Member

    Jan 15, 2010
    42
    1

    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: Feb 1, 2010
  8. electronic_noob

    Thread Starter Member

    Jan 15, 2010
    42
    1
    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: Feb 1, 2010
  9. electronic_noob

    Thread Starter Member

    Jan 15, 2010
    42
    1
    this is my connection, I use maxrs232 i think this is what they called the driver to make all voltage positive...am i right?
     
  10. electronic_noob

    Thread Starter Member

    Jan 15, 2010
    42
    1
    Ive included the datasheet of my MAX232,
     
  11. electronic_noob

    Thread Starter Member

    Jan 15, 2010
    42
    1
    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
     
  12. electronic_noob

    Thread Starter Member

    Jan 15, 2010
    42
    1
    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
     
  13. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
  14. electronic_noob

    Thread Starter Member

    Jan 15, 2010
    42
    1
    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!!!!!!!!!
     
Loading...