CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

help me with this code

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
micro17



Joined: 02 Mar 2014
Posts: 14

View user's profile Send private message

help me with this code
PostPosted: Sun Aug 02, 2015 11:32 am     Reply with quote

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 ********************/
 
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Sun Aug 02, 2015 12:06 pm     Reply with quote

Have you actually checked your chip is running?.

Also have you double checked there isn't something like a short somewhere?.
micro17



Joined: 02 Mar 2014
Posts: 14

View user's profile Send private message

PostPosted: Sun Aug 02, 2015 12:08 pm     Reply with quote

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
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Sun Aug 02, 2015 12:12 pm     Reply with quote

You say 330 in the comments.. Smile

Saw this after I originally posted, edited the post to remove this, but you had replied already.

What compiler version?.
micro17



Joined: 02 Mar 2014
Posts: 14

View user's profile Send private message

PostPosted: Sun Aug 02, 2015 12:16 pm     Reply with quote

not have 330 ohm Smile

PCWHD 5.042
micro17



Joined: 02 Mar 2014
Posts: 14

View user's profile Send private message

PostPosted: Sun Aug 02, 2015 1:07 pm     Reply with quote

work...bad connection on pot, solved

Thank you, Ttelmah
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group