Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16F876A with C, don't run.

Status
Not open for further replies.
On the code you provided, in the main loop you are only turning on the LED and never turning it back off with the 'bcf' command. On the asm file, that I provided, I think you selected 'relocateable' code instead of 'absolute'. I'm not at my main computer right now, the asm file is generated by mikroC, and may not be used directly without modifications -- I'll have to check in the morning.
 
Updated ASM file

Here is a asm version of the MikroC program that I wrote to flash the RGB LED. Hope this helps.
 

Attachments

  • Flash_LED.ASM
    6.2 KB · Views: 105
Here is a asm version of the MikroC program that I wrote to flash the RGB LED. Hope this helps.
Rmain, in your code you define the _config the OSC to "_RC_OSC" but, in my circuit i use the crystal 20MHZ. The correct would be "_HS_OSC" ?

Tanks
 
Yep, sorry I meant to lookup the HS osc fuse, but I forgot. I don't have a 876A to test on.
 
Here is a asm version of the MikroC program that I wrote to flash the RGB LED. Hope this helps.

Congratulation Rmain... i just changed the "_RC_OSC" to "_HS_OSC" and my 3 leds power on, intercaling in 1 second. But, after a restart (power off the batery), the led's not power on. In third attempt it's power on. Maybe is necessary one code reset in begin ? But, i think important that my circuit is good. OK ? Why the code C, don't run ?
Can you help me now, to make the code C run ?
 
I've been looking into that, the CCS compiler has an example LED flash program that I think you should modify to work with your LEDs. I'm trying it out with a 16F818 right now. The one thing that I have noticed is that their example program does not use the '#USE FAST_IO' directives.
 
Ok, I got a Bi-color LED working with the 16F818. The program is two files, the c source file and the header file which contains the defines and fuses. The CCS compiler project wizard made the two files. You'll have to open the header file in order to modify it. Use the 'OPEN Any File' option. Also note that the '#USE FAST_IO' was not used. You should be able to modify the program to use with your RGB LED. Take the setup_oscillator line out as I use the internal oscillator with the 16F818. You'll also have to modify the delay define for the 20 Mhz.

The C source file: Flash_LED_818.c
C:
#include <Flash_LED_818.h>



void main()
{
   setup_oscillator( OSC_8MHZ );
   setup_adc_ports(NO_ANALOGS);

    //Example blinking LED program
    while(true){
      output_high(LED_RED);         // Turn on RED LED
      delay_ms(DELAY);
      output_low(LED_RED);
      output_high(LED_YELLOW);      // Turn on YELLOW LED
      delay_ms(DELAY);
      output_high(LED_RED);         // Turn on both to produce ORANGE
      delay_ms(DELAY);
      output_low(LED_RED);          // Turn off both LEDs
      output_low(LED_YELLOW);
      delay_ms(DELAY);
    }

}

The header file: Flash_LED_818.h
C:
#include <16F818.h>
#device adc=16

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES WRT                      //Program Memory Write Protected

#use delay(int=8000000)

#define LED_RED PIN_B0
#define LED_YELLOW PIN_B1
#define DELAY 1000
 
Ok, I got a Bi-color LED working with the 16F818. The program is two files, the c source file and the header file which contains the defines and fuses. The CCS compiler project wizard made the two files. You'll have to open the header file in order to modify it. Use the 'OPEN Any File' option. Also note that the '#USE FAST_IO' was not used. You should be able to modify the program to use with your RGB LED. Take the setup_oscillator line out as I use the internal oscillator with the 16F818. You'll also have to modify the delay define for the 20 Mhz.

The C source file: Flash_LED_818.c
C:
#include <Flash_LED_818.h>



void main()
{
   setup_oscillator( OSC_8MHZ );
   setup_adc_ports(NO_ANALOGS);

    //Example blinking LED program
    while(true){
      output_high(LED_RED);         // Turn on RED LED
      delay_ms(DELAY);
      output_low(LED_RED);
      output_high(LED_YELLOW);      // Turn on YELLOW LED
      delay_ms(DELAY);
      output_high(LED_RED);         // Turn on both to produce ORANGE
      delay_ms(DELAY);
      output_low(LED_RED);          // Turn off both LEDs
      output_low(LED_YELLOW);
      delay_ms(DELAY);
    }

}

The header file: Flash_LED_818.h
C:
#include <16F818.h>
#device adc=16

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES WRT                      //Program Memory Write Protected

#use delay(int=8000000)

#define LED_RED PIN_B0
#define LED_YELLOW PIN_B1
#define DELAY 1000

Rmain... the result is FAIL.

Look my code:
Code:
#include "D:\Projetos\Estacionamento\Led_C_Compiler\piscapjt.h"
 
void main()
{
   setup_oscillator( OSC_20MHZ );
   setup_adc_ports(NO_ANALOGS);
 
    //Example blinking LED program
    while(true){
      output_high(LED_RED); // Turn on RED LED
      delay_ms(DELAY);
      output_low(LED_RED);
      output_high(LED_GREEN); // Turn on YELLOW LED
      delay_ms(DELAY);
     utput_low(LED_GREEN);
      output_high(LED_BLUE); // Turn on both to produce ORANGE
      delay_ms(DELAY);
      output_low(LED_BLUE); // Turn off both LEDs
      delay_ms(DELAY);
    }
}

HEADER CODE:
Code:
#include <16F876A.h>
//#device adc=8      // I tested with 8 and 16, both not run.
#device adc=16
#FUSES NOWDT                    //No Watch Dog Timer
//#FUSES INTRC_IO                //Internal RC Osc, no CLKOUT
#FUSES HS                   //High speed Osc (20mhz) 
//#FUSES NOMCLR                   //Master Clear pin used for I/O  ---> It's fail to build, no suport my pic. --> http://www.ccsinfo.com/forum/viewtopic.php?t=43458
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
//#FUSES WRT                      //Program Memory Write Protected --> it's fail to build.
 
#use DELAY(CLOCK=20000000)  // --> changed to 20MHZ

#define LED_RED PIN_B0
#define LED_GREEN PIN_B1
#define LED_BLUE PIN_B2
#define DELAY 1000
 
Your 16F876A does not have an internal oscillator, so remove the

'setup_oscillator( OSC_20MHZ );'

You might also want to run the project wizard which will setup the fuses and basic configuration, etc for your PIC16F876A and then edit it as needed. Try that and then copy the program that you have written in the new project.
 
Does that mean you got it working?
 
Your 16F876A does not have an internal oscillator, so remove the

'setup_oscillator( OSC_20MHZ );'

You might also want to run the project wizard which will setup the fuses and basic configuration, etc for your PIC16F876A and then edit it as needed. Try that and then copy the program that you have written in the new project.

Tank you very much, Rmain.....

The RGB is Power ON.....

Look the correct config:

MAIN:
Code:
#include "D:\Projetos\Estacionamento\Led_C_Compiler\PISCA_LED_FORUM_C.h"


void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   // TODO: USER CODE!!
   
   //setup_oscillator( OSC_8MHZ );
   //setup_adc_ports(NO_ANALOGS);
 
    //Example blinking LED program
    while(true){
      output_high(LED_RED); // Turn on RED LED
      delay_ms(DELAY);
      output_low(LED_RED);
      output_high(LED_GREEN); // Turn on YELLOW LED
      delay_ms(DELAY);
      output_low(LED_GREEN);
      output_high(LED_BLUE); // Turn on both to produce ORANGE
      delay_ms(DELAY);
      output_low(LED_BLUE); // Turn off both LEDs
      delay_ms(DELAY);
    }

}

HEADER CODE:
Code:
#include <16F876A.h>
#device adc=8

#FUSES NOWDT                 	//No Watch Dog Timer
#FUSES HS                    	//High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT                 	//No Power Up Timer
#FUSES NOPROTECT             	//Code not protected from reading
#FUSES NODEBUG               	//No Debug mode for ICD
#FUSES NOBROWNOUT            	//No brownout reset
#FUSES NOLVP                 	//No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                 	//No EE protection
#FUSES NOWRT                 	//Program memory not write protected
#FUSES RESERVED              	//Used to set the reserved FUSE bits

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#define LED_RED PIN_B0
#define LED_GREEN PIN_B1
#define LED_BLUE PIN_B2
#define DELAY 1000

Tank very much, Rmain !! I hope help you in the future.
 
No problem. :) Glad to help.
 
Status
Not open for further replies.

Latest threads

Back
Top