Is there anyone know MicroC please?

I'm a student and ı have to make a project. I have done lot of researches about ADC ' s but ı really dont get it. Can anyone please help me atleast 1 part of my project ? I really just want to learn and do my own job.
My project is doing a smart home with especially C language (thats a requirement). All ı want is just controll a led with potentiometer or sensor (lm35&...). I tried to do with Analog Digital Convertor but ı cant find whats wrong. Here is my code;

void ADC_ISR () org IVT_ADDR_ADC
{
PORTD=ADCH;
ADCSRA |= (1<< ADSC);

}
void main()
{
DDRD=0xFF;
SREG_I_bit=1;
ADMUX=0x60;
ADCSRA=0X8E;
ADSC_bit=1;
while(1);
}

Which micro controller board are you using?

deger won't end up being a scalar and an array I hope.

What are you thinking this infinite loop will be doing for you?

a7

Atmega328p

Yes there is an error, sorry ım kind a new in this

Use Arduino UNO Board (Fig-1) which contains ATmega328P MCU and enjoy MCU hardware/programming to modulate the brightness of Led as you rotate the wiper of the potentiometer.
UNOBoardPic
Figure-1:

Actually ı dont want to control brıghtness what ı want is when potentiometer or sensor like lm35 pass the certain level (potentiometer's half) led should light up.

Right, but are you using the Arduino IDE and the traditional setup/loop idea?

Do you have any complete code that compiles and runs, even if it isn't yet doing what you want?

a7

Ofcourse here it is;
sbit led at PORTD.B0;
void main() {
int i=0;
DDRD.B0=1;
led=0;
while(1)
{
TCNT0=-250;
TCCR0B=0x02;
while((TIFR0&0x01)==0);
i++;
if(i==8000)
{
led=~led;
i=0;
}
TCCR0B=0;
TIFR0=1;
}
}

Do you have an Arduino UNO Board like Fig-1 of post #6?

Yes ı have

Looks like you think that will make an LED turn on and off. All it does is make led change from 1 to 0 and back… you have to actually put that on the pin to make the attached LED follow along…

And that code won't compile, there is no declaration of led.

Unless you somewhere that

 sbit led at PORTD.B0;

makes sense. Doesn't look like C/C++.

a7

Thank you for noticing that but that is not solving my problem, ı'm having trouble transferring ''Led on if potentiometer pass certain level''

I suggest you to start formatting your code and post it in tags so we can read it better.

Use the </> form the tool bar in the message composition window.

Also I suggest you to use Serial.print() statements to see what values you are getting from the a/d conversion. And other places to trace the flow.

Lastly I ask why? aren't you just using analogRead()?

You could use it to get this working, then if you really feel like you need to start messing with the registers on your hands and knees in the dark crying for help…

a7

Bro ı have to use MicroC , MicroC doesnt have analogread command. I have done lot of researches and all ı found is analogread. If i could use analogread ı dont have to cry for help here sorry for that.
I will post my code ın minutes thank you so much for helping me.

It might be worth installing the Arduino IDE and then you will be able to read the source code of analogRead.

Can ı write with MicroC after that ?

I imagine so. If you follow the rabbit hole far enough, I think you'll get to the nitty gritty of how to command the analog hardware. You may wish to simply copy analogRead and whatever it calls into your MicroC program.

Is it a pure C compiler or will it permit C++ constructs too?

Do you have LM35 analog temperature sensor?

void ADC_ISR () org IVT_ADDR_ADC
{
PORTD=ADCH;
ADCSRA |= (1<< ADSC);

}
void main()
{
DDRD=0xFF;
SREG_I_bit=1;
ADMUX=0x60;
ADCSRA=0X8E;
ADSC_bit=1;
while(1);
}