Program to 16f877a doesn't work

Jose Luis
2008-10-15
2013-03-12
  • Jose Luis
    Jose Luis
    2008-10-15

    Hy Guys,

    I have wrote the following code:
    ----------------------------------------------------------------------
    #define __16f877a
    #include <pic/pic16f877a.h>

    typedef unsigned int config;
    config at 0x2007 __CONFIG = _XT_OSC & _WDT_OFF;

    void main(void)
    {
           while(1)
           {
                  PORTD = 0x55;
           }
    }
    ----------------------------------------------------------------------

    I'm using the following command to compile:
    sdcc "mysource.c" -o "c:\temp" --less-pedantic -mpic14 -p16f877a

    The SDCC generates the asm and hex file normally and I can load and send normally the code to Microcontroller using the MPLAB without errors. But when I run the application the PORTD is not set.

    PS: I'm setting the bits configuration mannualy in MPLAB and I have tested a hex file compiled in MicroC and the same code compiled by MicroC works.

    Have anybody any idea of what's happening?

    Thanks for all.

     
    • Lucas Coppio
      Lucas Coppio
      2008-10-15

      its because you HAVE to set the portD... and also the other configs

      try this

      //#define __16f877a  this one isn't necessary in THIS case
      #include <pic/pic16f877a.h>

      typedef unsigned int        WORD;        /* Unsigned 16-bit */
      WORD at 0x2007 CONFIG = _HS_OSC & _WDT_OFF & _PWRTE_OFF & _BODEN_OFF & _LVP_OFF & _CPD_OFF & _WRT_OFF & _DEBUG_OFF & _CP_OFF;  //HS = 20MHz

      void main(void)
          {

      TRISD = 0xFF //you forgot THIS!!!!!!!

      while(1) {
              PORTD = 0x55;
              }
          }

       
      • Lucas Coppio
        Lucas Coppio
        2008-10-15

        Sorry try this  instead

        //#define __16f877a this one isn't necessary in THIS case
        #include <pic/pic16f877a.h> 

        typedef unsigned int WORD; /* Unsigned 16-bit */
        WORD at 0x2007 CONFIG = _HS_OSC & _WDT_OFF & _PWRTE_OFF & _BODEN_OFF & _LVP_OFF & _CPD_OFF & _WRT_OFF & _DEBUG_OFF & _CP_OFF; //HS = 20MHz

        void main(void) 

        TRISD = 0x00 //you forgot THIS!!!!!!! (output = 0, INPUT = 1)

        while(1) { 
        PORTD = 0x55; 

        }