Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Need some help for pic12f675

Status
Not open for further replies.

uzzalpic

Junior Member level 2
Joined
Mar 24, 2014
Messages
24
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Activity points
189
Hi, I need some help for my code. Plz help me ....

Code:
#define ON 1
#define OFF 0

sbit red_led at GP4_bit;
sbit green_led at GP5_bit;
sbit yellow_led1 at GP1_bit;
sbit yellow_led2 at GP2_bit;

unsigned char led_blink = 0;
unsigned int adc_value;

void delay_start()
{
 green_led = ON;
 delay_ms(500);
 green_led = OFF;
 delay_ms(500);
 green_led = ON;
 delay_ms(500);
 green_led = OFF;
 delay_ms(500);
}

//Timer1
//Prescaler 1:4; TMR1 Preload = 3036; Actual Interrupt Time : 250 ms

//Place/Copy this part in declaration section
void InitTimer1(){
  T1CON	      = 0x21;
  TMR1IF_bit  = 0;
  TMR1H	      = 0x0B;
  TMR1L	      = 0xDC;
  TMR1IE_bit  = 1;
  INTCON      = 0xC0;
}

void Interrupt(){
  if (TMR1IF_bit){
    TMR1IF_bit = 0;
    TMR1H	 = 0x0B;
    TMR1L	 = 0xDC;
    //Enter your code here
       if((TMR1IE_bit) && (TMR1IF_bit)) {
        if(++led_blink == 1) {
           led_blink = 0;
           green_led = ~green_led;

        }
       }
  }
}



void main() {
 CMCON = 0x07;
 ANSEL = 0x01;
 ADCON0 = 0x01;

 TRISIO = 0x01;
 GPIO = 0x00;

 InitTimer1();
 delay_start();
 ADC_Init();

 while(1){
    adc_value = ADC_Read(0);
    delay_ms(10);

    if((adc_value >= 200) && (adc_value <= 412))
    {

      [COLOR="#FF0000"][B] Here i want to green led blink -------------[/B][/COLOR]
       yellow_led1 = ON;
       yellow_led2 = ON;
    }

    if(adc_value > 413)
    {
      green_led = ON;      [B][COLOR="#FF0000"]Here green led will not blink  just will on[/COLOR][/B]
      yellow_led1 = OFF;
      yellow_led2 = OFF;
    }
 }

}
 

Hi,

Generally:
* your title is really not descriptive.
* And one has to scroll through your code to find something like a question...

****
To your problem:
The problem is, that you obviously didn´t draw a sketch with time line. It should include the flow of the main loop and the blinking of your LED.
--> decide how long (in time) your main loop is and what blinking timing (frequency) you want.
It does neither need to be perfect, nor to be very exact. But it will visualize the problem. Then the solution is more easy to find.
--> take a sheet of paper and a pencil.

Maybe you find someone that writes the code for you... but I assume he will need the same informations..
So I expect he will ask you: What blikning frequency do you want? How often per second do you expect the main loop to run?


Klaus
 

Hi uzzalpic;

I did not study the rest of the code, but your interrupt function has a fatal error that causes the program surely does not work:
Code:
void Interrupt(){
  if (TMR1IF_bit){
    [COLOR="#FF0000"]TMR1IF_bit = 0;[/COLOR]
    TMR1H = 0x0B;
    TMR1L = 0xDC;
    //Enter your code here
    if((TMR1IE_bit) [COLOR="#FF0000"]&& (TMR1IF_bit)) [/COLOR]{ [COLOR="#008000"]// ???? (never true !!)[/COLOR]
        if(++led_blink == 1) {
           led_blink = 0;
           green_led = ~green_led;
        }
    }
  }
}

Instead, try this code:
Code:
void Interrupt() {
  if (TMR1IE_bit && TMR1IF_bit) {
    TMR1L = 0xDC;
    TMR1H = 0x0B;
    if (led_blink) { [COLOR="#008000"]// use this to switch on-off the blinking in main()[/COLOR]
       green_led = ~green_led;
    }
    TMR1IF_bit = 0;
  }
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top