View previous topic :: View next topic |
Author |
Message |
micro17
Joined: 02 Mar 2014 Posts: 14
|
help me with this code |
Posted: Sun Aug 02, 2015 11:32 am |
|
|
Hi all
Please help me with this code, work in proteus but in breadboard not....the LED only stay bright/ON
Thank you
Code: |
/*
LED on gpio.1 blinks at rate controlled by
potentiometer connected to gpio.0
*/
#include <12f683.h>
#device adc=10
#use delay(clock=8000000)
#fuses nowdt,intrc_io,put,noprotect,brownout,nomclr,nocpd
#define LED PIN_A1 // define pin for LED
int16 ad = 0; // holds 10-bit a/d value 0 to 1023
void init(void) // hardware initialization
{
output_low(LED); // LED off on boot
set_tris_a(0x01); // gpio.0 input, rest outputs
setup_oscillator(OSC_8MHZ); // set for 8MHz internal osc
setup_adc_ports(AN0_ANALOG); // a/d enabled on gpio.0
setup_adc(ADC_CLOCK_DIV_16); // a/d clock /16 @8MHz,Tad=2uS
setup_comparator(NC_NC_NC_NC); // disable comparator module
}
void Blink(int16 adval)
{
int16 rate;
rate=adval*2; // ~0-2Hz blink rate
output_high(LED); // LED on. gpio.1 o--/\/\/\---|>|---o gnd
delay_ms(rate); // blink delay 330 LED
output_low(LED); // LED off
delay_ms(rate); // delay before return
}
void main(void)
{
init(); // configure hardware
while(1) // continuous loop
{
set_adc_channel(0);// set a/d channel to gpio.0
delay_us(50); // delay for acquisition
ad = read_adc(); // read a/d into ad variable
Blink(ad); // blink LED at rate set by 10-bit a/d value
}
}
/******************* The End ********************/
|
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Sun Aug 02, 2015 12:06 pm |
|
|
Have you actually checked your chip is running?.
Also have you double checked there isn't something like a short somewhere?. |
|
![](templates/subSilver/images/spacer.gif) |
micro17
Joined: 02 Mar 2014 Posts: 14
|
|
Posted: Sun Aug 02, 2015 12:08 pm |
|
|
yes 300 ohm resistor
I try 5k and 10 k pot
Last edited by micro17 on Sun Aug 02, 2015 12:15 pm; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Sun Aug 02, 2015 12:12 pm |
|
|
You say 330 in the comments..
Saw this after I originally posted, edited the post to remove this, but you had replied already.
What compiler version?. |
|
![](templates/subSilver/images/spacer.gif) |
micro17
Joined: 02 Mar 2014 Posts: 14
|
|
Posted: Sun Aug 02, 2015 12:16 pm |
|
|
not have 330 ohm
PCWHD 5.042 |
|
![](templates/subSilver/images/spacer.gif) |
micro17
Joined: 02 Mar 2014 Posts: 14
|
|
Posted: Sun Aug 02, 2015 1:07 pm |
|
|
work...bad connection on pot, solved
Thank you, Ttelmah |
|
![](templates/subSilver/images/spacer.gif) |
|