Jump to content


  • Content Count

  • Joined

  • Last visited

Posts posted by Hobknob

  1. You can tell that the processor has been watchdog reset by checking bit 4 (TO bit) in the STATUS register. If the processor has been watchdog reset this bit is 0.


    I guess you are talking about using timer TMR0, for you interrupt driven serial comms. One bit being transmitted every interrupt.


    The limitation with TMR0 and watchdog, is that they have only one prescaler between them. It can be switched to be used either by TMR0 or watchdog, but not both at the same time.

    The watchdog will still work if TMR0 is using the prescaler, but has a much shorter timeout period.


    Hope this helps




  2. The problem is you have a delay after switching on your LED's, but not after you switch them off.

    This means that are off for such a short time you won't see it.


    I've added an additional delay in the code below to make it work.


    //Timing settings

    #pragma CLOCK_FREQ 4000000


    void main(void)


      //Hardware Initialization

      disable_interrupt( GIE );

      set_bit( STATUS, RP0 );

      set_tris_a( 2 );

      set_tris_b( 0 );

      clear_bit( STATUS, RP0 );

      output_port_a( 0 );

      output_port_b( 0 );





          delay_s(1); // delay to keep leds on for one second


          delay_s(1); // delay to keeps led off for one second






  3. I have seen a circuit that connects the PC serial port to PIC with a 22K ohms direct connect, and the author claims that it works. I am going to try that. ()

    Becareful. The circuit you are talking about will almost certaininly not being meeting the RS232 specification, although it may work on one PC.


    The RS232 spec requires a minimum of +/-3V at the receiver, so if you want your PC to receive data from you PIC you need to provide voltages at least around these levels.


    If you just want your pic to recieve data from you PC, then a couple of resistors and clamping diodes should work pretty well, but the interace does not meet the RS232 spec.


    Something like a max232 does a nice solution to providing at interface that meets the RS232 spec.


    Another thing to bear in mind is that different PC manufactures RS232 ports vary. So an out of specification designed that works with one PC may not work with another.


    If you are really interested there are pages on the web (sorry cant remember where) about designing micro-power circuits that interface to the RS232 port and get all their power from there two (a normal mouse does this), but these designs have to be very clever to work with all PC's.


    Have Fun





  4. Francesco: Thank you for the answare but my question was: how can I put some bytes in .hex file, that during programming (by MPLAB), are written in the PIC16F877 EEPROM area?


    This data can be added to the .hex file.

    It needs to be programmed to PIC address 0x2100h and onwards.


    Here an extract that does that. Note that the address 2100h is multiplied by 2 ie  4200h is used because each location consists of two bytes.












    so to add data to eprom from a .asm file you just add

    org 0x2100

    dw 12,34,56,78

    to set data in EEPROM at program time.



    ****This is what you really want!******

    :) :) :)

    To add eprom data in your C code add the following, do NOT do this inside a function body - otherwise it can get optimised away!


    asm last_addr equ $ ; save current address for assembly


    asm org 0x2100 ; Eprom address when programming PIC

    asm dw 12,34,56,78 ; set our bytes in eprom - only when programmed!


    asm org last_addr ; restore current address for assembly to contniue as normal


    void main()


          my code.....



    This generates the correct stuff in the .hex - I have not tried programming a device, so please let me know if this works.


    The only other thing is that your programmer software correctly handles EEPROM programming.




  5. I would recommend not setting the INTCON register.

    Leave it to its power on reset value.


    You haven't defined an interrupt handler, you don't need one for what you are doing, but you are enabling some interrupts.


    Not sure what device your using, and hence what sources of interrupts are available.


    If an interrupt is generated, it jumps the control to address 0004, if this doesn't jump to an interrupt handler it may be restarting you program continously. So if the code enters the delay loop it doesn't stay there for long !


    Hope this work for ya.




  6. You haven't explained what is happening, other than it doesn't work so this makes it real hard to help.


    Also you have only supplied a tiny fragment of code, break you code down to just a simple main routine and supply the complete code explaining what is happening.


    A classic fault here is leaving the watchdog timer enabled, so the processor keeps getting reset so the results are what are expected


    Hope this helps.



  • Create New...