Led not blinking.

JohnInTX

Joined Jun 26, 2012
4,787
It's weird sometimes how that works. You worry about the stuff you are trying to learn and something simple like a bad LED scorches you.. Been there.
Well done!
 

Thread Starter

lemario

Joined Jan 31, 2016
22
Thank you again for all the help. I am in programming course and most of my bugs are ";" or syntax errors :p.

And it was 3 bad leds.....

:)
 

spinnaker

Joined Oct 29, 2009
7,830
This is why reliable test equipment is essential to make this hobby a lot easier. You don't need to spend a fortune. Start off with a logic probe and / or voltmeter. Later yo might want to add a scope and a logic analyzer. If anything they are a lot of fun to play with. My logic analyzer is a pain to setup but once done I really like using it. It has helped me out of a jam more than once.
 

Picbuster

Joined Dec 2, 2013
1,058
Hello. This is my first time messing with a microcontroller. I am trying this tutorial:

CIRCUIT: http://postimg.org/image/lasta61k1/
CHIP: 12f683
COMPILER: mikroC PRO for PIC v.6.6.1


I write the program just fine but the led does not work.
I might be doing some stupid mistakes but its my first time so don't shop my head of please.

code:
C:
void main(void) {
      TRISIO.B2 = 0;
      while(1)
      {
              GPIO.B2 = 1;
              Delay_ms(1000);
              GPIO.B2 = 0;
              Delay_ms(1000);
      }
}
Mod edit: added code tags
Here is a working example Led @ pin 5
I also include an ADC example and explanation in short hand.
Small advice: please use microchip xc8 compiler its free and works good.
The free version is able to fulfil most of the hobbyists needs.

Good luck.
C:
// Xc8 compiler
#include <htc.h>
#include <pic12f675.h>
#include <xc.h>
#define _XTAL_FREQ 4000000  // Needed for delay_ms macro
 
//#pragma CONFIG(FOSC_INTRCIO & CP_OFF & MCLRE_ON & WDTE_OFF); << depending from your wishes

#define Output GPIO5
#define Voeding_On GPIO4
#define Led GPIO2  // pin5

int Wanted_value;
int cnt;
int Flash;
unsigned int result;


//=========================== interrupts ====================
static void interrupt
peripheral_interrupt(void)

/*
//================== when adc under interupt is needed========
//================== set the int  (  ADIE=1; 
// ========== ask in main for ana do ==>  ADCON0bits.GO = 1;
// == or  led a timer do it for you
// == doing so will provide you always an value

if (ADIF)
  {
  ADIF=0;
//-------------------- read voltage  -------------------------
   while (ADCON0bits.GO_DONE);
   result = ADRESH; 
   result <<=8;  // shift highbyte left
   result |= ADRESL;  // and do low
//-------------------------------------

  }
*/


{

//======================== timer =================================
if (TMR0IF)
   TMR0IF=0;
cnt++;
 
   Flash++;
   if (Flash < 800){Led=0;} 
   if (Flash > 1000 + (3000 * !Output))
{
   Flash=0;
   Led= 1; //!Led; on
   }
 
  else
  {
  Led=1; 
  }
//------------------------------------------------------------------
if (cnt >6000){cnt=0;}
}
//================  end of interrupt ========================


 
void main()
{
   OPTION_REG = 0b10000000;
ADCON0 =0b10000001; // bit 7 right justfied bit 1 conversion is operating
ANSEL = 0b010001;  // to select analog input GPIo0
 
VRCON = 0x00;
CMCON = 0x07;
//==========  ADIE=1;  used when adc working under int
TMR0IE=1;
GIE=1;

TRISIO0 = 1;  // set for input
TRISIO1 = 0;
TRISIO2 = 0;
TRISIO4 = 0;
TRISIO5 = 0;
// ============================== start
GPIO1=0;
cnt=1;  // wait
    while(cnt){}
  Output=0; // flash fast
 
//======================= mail loop =====================
  while(1)
{
 
//======  @ 5Vreference and 10bits  1024 = 5/1024 = 0,00488 V/bit input-->>  (204.8) 204 bits approx per volt

//-------------------- read voltage  -------------------------
ADCON0bits.GO = 1;
   while (ADCON0bits.GO_DONE);
   result = ADRESH; 
   result <<=8;  // shift highbyte left
   result |= ADRESL;  // and do low
 
//-------------------------------------

  if(result >=Wanted_value)  //
  {
  Output=1; // flash slow
  // your prog here.

  } 
 
} 
}
Mod edit: Added code tags
 
Last edited by a moderator:
Top