Here is a working example Led @ pin 5Hello. 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:
Mod edit: added code tagsC:void main(void) { TRISIO.B2 = 0; while(1) { GPIO.B2 = 1; Delay_ms(1000); GPIO.B2 = 0; Delay_ms(1000); } }
// 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.
}
}
}