PORTB =0b00111111; vs port bit (RB1_bit=0;)

Status
Not open for further replies.

now OK low volt cut off function ....
thank u Agnes my dear sir rmain1972
and what u about BlinkLED1 & Quake start sw.
 
Last edited:
my comments are in post #54.
this is ok
Code:
void BlinkLED1(void)
{
   int x;
   
   for (x=0; x<=9; x++) // Repeat 10 times, count from 0 to 9
   {
      output_high(L1);
      delay_ms(BLINK_DELAY);
      output_low(L1);
     if ((input(SW1)==1)  && delay_ms(1)) // Quake start hear if SW1 is  on any time 1 sec
      goto(NORMAL_VOLTAGE);
   }
 

In the line above, delay_ms(1) isn't correct in that context. The code executes, but it's not right. All you are doing in this block of code is testing for SW1==1 and then executing a delay of one ms. I don't think that is what you want. You want to test that one ms (or is it one second?) has passed. We are going to have to use one of the 676 timers with a count variable to test that time has passed (or look for a built in function, if it exists).

Also you shouldn't use goto XYZ unless you absolutely must. And it should be inside the same routine in which it is used. When you go into a routine, the program counter is pushed unto the stack, by jumping out of the routine with a goto doesn't pull the return address from the stack. Do the goto 8 times, and your program crashes because the stack is full.

First, I think the line goto (NORMAL_VOLTAGE) is wrong because NORMAL_VOLTAGE is a define, not a label.

In this case, I would replace goto (NORMAL_VOLTAGE); with a break statement and a flag. You are inside of a loop and the break statement will exit the loop.

C:
// QuickStart_flag defined as a global variable
int1 QuickStart_flag;

void BlinkLED1(void)
{
   int x;
 
   for (x=0; x<=9; x++) // Repeat 10 times, count from 0 to 9
   {
      output_high(L1);
      delay_ms(BLINK_DELAY);
      output_low(L1);
      if ((input(SW1)==1) && (time_elasped()<1000) ) // Quake start hear if SW1 is  on any time 1 sec
      {
          QuickStart_flag;=1;
          break;
      }
    }
}
    // we would test for QuickStart_flag elsewhere in code, probably the switch case staement.
    // also note that time_elasped() is only an example function that would return the time_elasped, not defined here.

Let me do some thinking about the timers.
 
Last edited:
now error show as...
>>> Warning 203 "test_676_CCS.c" Line 84(1,1): Condition always TRUE
*** Error 12 "test_676_CCS.c" Line 248(32,44): Undefined identifier time_elasped

1Errors, 1 Warnings.
where we wrong ?
 
Last edited:
Try this, I think this is what you want.
 

Attachments

  • test_676_CCS.c
    9.2 KB · Views: 159
  • test_676_CCS_01.h
    361 bytes · Views: 138
Not sure about that unless its the call 0x3ff. Not sure why the compiler puts that in there.

EDIT: There is no call 0x3ff. It is jumping directly to the return from interrupt, and seems to be crashing at the RETIE instruction. It was working in MPLAB SIM. I'll try it again.
EDIT2: There is a call 0x3ff at instruction 038.

The code goes
MOVLW 02
MOVWF PCLATH (0A)
GOTO 38

38:
Call 0x3ff
 
Last edited:
Probably going to have to put the LED1 blink code in the interrupt.

Pseudo code for interrupt routine:
Turn LED1 on
Count # of ms that have passed
Once we reach 1000 (one sec), Turn off LED1
count # of ms that have passed
Once we reach 1000 (one sec), increment LED1count variable, to determine the number of times we have blinked LED1
repeat 10 times
 

1 sec on time & 1 sec off time = total on\off time is 2 sec
if i set
when Counting passed 90 times=total 180 sec ...OK !
in duration of 180 sec (3 min) , adc sensing =???
ofter 180 sec (3 min) , adc sensing manes relay
my quation is
Code:
in duration of 180 sec (3 min) , adc sensing =???
we need both function work same time
 

Yes, you would count to 90 at a blink rate of 1 second on and 1 second off for a total of 180 sec or 3 min. The ADC sensing would be done concurrently because the ADC code would be executing, and at a 1 ms time interval, the interrupt would occur.
 
Yes, you would count to 90 at a blink rate of 1 second on and 1 second off for a total of 180 sec or 3 min. The ADC sensing would be done concurrently because the ADC code would be executing, and at a 1 ms time interval, the interrupt would occur.

both function work same time not possible ?
 
There are two ways to do it. Put the code in a interrupt as I suggest, or put the blinkled1 code in with the ADC code. With the interrupt executing at 1 ms, you can count up to 3 min. You'd have to figure out a way to count up to 3 min if you put the blinkled1 code with the ADC code. It's just a matter of how you want to do it. Either way, both sets of code are executing at the same time.
 
it is right way...
Code:
void main()
{
   //Timer1 Init
   setup_timer_1(T1_INTERNAL | T1_DIV_BY_2);      // Use Internal Timer, Prescaler = 1 : 2
   set_timer1(60545);                        // Set Timer1 register to 1 ms @ 4 Mhz

   //ADC Init
   setup_adc_ports(sAN0);
   setup_adc(ADC_CLOCK_DIV_32);
   ADFM = 1;                      //AD Result Right Justified
   setup_comparator(NC_NC);

   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);

  
    
      voltage_type = ProcessMains();

     // Quick start here if SW1 is  on any time 1 sec
     // time_elasped set in interrupt
     if ( (QuickStart_flag == 1) && (time_elasped<1) )//&& (voltage_type == LOW_VOLTAGE) )
          voltage_type = NORMAL_VOLTAGE;
      
      switch(voltage_type)
      {
         case HIGH_VOLTAGE:
            output_high(BZR);    // Create Sound
            output_low(RL5);     // Relay Off
            BlinkLED2();
            break;
            
         case LOW_VOLTAGE:
            output_high(BZR);    // Create Sound
            output_low(RL5);     // Relay Off
            BlinkLED2();
            break;
            
         case NORMAL_VOLTAGE:
            output_low(BZR);
            output_high(RL5);
            //BlinkLED1();
            output_high(L1);
            break;
         
         default:
            //We shouldn't get here
                        while (1)
   {
      //led1 blink mains normal ,led1 blink & Reads ADC
        // both are work in same time. not one by one.
        //if led1 blink duration complet then it no blink agen.
       if (BlinkMains_flag==0)
      {
         BlinkLED1();
         BlinkMains_flag=1;
      }
            break;
      }
    }  
} // End Main
 

I don't think so, because your never going to get out of the endless loop. EDIT: In order for the default section to be executed, ProcessMains() would have to return something other than LOW_VOLTAGE, HIGH_VOLTAGE, OR NORMAL_VOLTAGE.
 
Last edited:
Try this. The LED should blink in the interrupt for 3 mins, and then stop. I also added a delay after the A/D conversion because MPLAB SIM kept complaing that a new conversion should not be started until after 2 TADs have passed. The delay is 5 ms. The interrupt fires every 10 ms. Take a look, and let me know.
 

Attachments

  • test_676_CCS.c
    9.5 KB · Views: 148

now working OK. but led1 action only on type not blink .right now i check it only oshon soft ,not real card .on real card i check it letter .
 
now working OK. but led1 action only on type not blink .right now i check it only oshon soft ,not real card .on real card i check it letter .

Did you wait for the simulated 1 sec time to pass, because it it was working in MPLAB SIM.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…