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.

Mikro C pro code help

Status
Not open for further replies.

akter

Newbie level 2
Joined
Aug 18, 2014
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
11
i m new in microcontroller, please help me,
i want to add another condition like this

if PortA=0x0F for 20 Seconds then Portd.f1=0;

otherwise everything will remain same.
please any one help me.

aaa.png



Code C++ - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
void main()
 
 
 
{
 
 
  CMCON = 0x07;
  ADCON1 = 0x06;
  
  TRISA = 0x0F;          //  input
  PORTA = 0x00;
 
  TRISD = 0x80;          //  output
  PORTD = 0x00;
 
 
 
 do
 
  {
 
 
   if(PORTA == 0x0F)
 
   {
       PORTD.F1 = 1;
    }
 
 
 
   else if(PORTA == 0x00)
   {
       PORTD.F1 = 0;
   }
}
while(1);            // Endless loop
}

 
Last edited by a moderator:

I have a timer running (usually 1mSec interrupts) and a function with prototype
Code:
// retrun true if  time in mSec has elapsed   - reset to start if reset is true
int mSecElapsed(const int reset, const long unsigned int time)
then the code would be something along the lines of
Code:
mSecElapsed(1,0);     //reset timer
// wait 20 seconds if PortA = 0x0F
while ((PortA==0x0F) && !mSecElapsed(0, 20000)) ;
// if 20 seconds elapsed and PortA = 0x0F
if((PortA==0x0F) && mSecElapsed(0, 20000)) 
   Portd.f1=0;
I am sure the logic can be improved with a bit of thought!

do you want to do anything else while waiting for the 20 seconds?

or would this work?
Code:
mSecElapsed(1,0);     //reset timer
while(1)
{
if(PortA!=0x0F)
   // PortA !=0x0F  reset timer etc
   { mSecElapsed(1,0);   Portd.f1=1; }
else
   // if 20 seconds elapsed and PortA = 0x0F
   if( mSecElapsed(0, 20000)) 
         Portd.f1=0;)
...     // do other things

}
 
Last edited:
  • Like
Reactions: akter

    akter

    Points: 2
    Helpful Answer Positive Rating
thank you very much
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top