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.

1 input 2 output with time delay

Status
Not open for further replies.

manishb2010

Newbie level 3
Joined
May 21, 2012
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,354
i have problem with timer access.
my application is like, after detection of input output relay become after set time both relay can set different time. so is it possible to use two timer(timer0 and timer1) in 89s52 at same time?
please suggest me how we can use it.
 

If your device has Timer0 and Timer1, you can absolutely use them independently.

Or, you can set up two software-based timers, that get their value from only only one of the timer modules. You can write firmware to use Timer0 to control many different actions/outputs, not just one output. For example, if you want to take "Action A" 250ms after the correct input is detected, but then take "Action B" 700ms after input is detected--you don't need two timers. Just set up Timer0 to be free-running, and then when your counter variable based on Timer0 (or whatever you decide) reaches 250ms, trigger "Action A", and then when it reaches 700ms, trigger "Action B".
 

thanking you for replying.
i want to use timer 1 for count down operation for which i had prepared following code ,but after detection of input signal the count down timer will not start, please suggest me what is the mistake.



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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
#include<regx52.h>
#include<stdio.h>
#include<string.h>
#include <intrins.h>
#include <stdlib.h>
#define ldata P0
sbit d7 = P0^7;
sbit rs = P2^0;
sbit rw = P2^1;
sbit en = P2^2;
sbit save=P2^7;
sbit sclk = P2^5;
sbit sda = P2^6;   
sbit start = P1^0;
sbit inc = P1^1;
sbit dec = P1^2;
sbit enter = P1^3;
//sbit v1 = P3^4;
sbit v2 = P3^5;
sbit l1 = P3^0;
 
unsigned char b[16];
unsigned char high2,low2,tik2;
float newvalue2, dummytimer2;
unsigned int timer12, timer22; 
void lcddata2(unsigned char);
void lcdcmd2(unsigned char);
void msdelay2(unsigned int);                          // 0xC0 for 2nd line and 0x80 for 1st line
void numdis2(unsigned char, unsigned int);
void num2(unsigned char, float);
void numwhole2(unsigned char, unsigned int);
void strwrt2(unsigned char, unsigned char *);
void wait_lcd2();
void clearb2();
void in2();
void start_s_eeprom2();
void send_byte_s_eeprom2(char);
char get_byte_s_eeprom2();
void stop_s_eeprom2();
void send_to_mem2(char, char);
unsigned int get_from_mem2(char);
void wait2();
void acknowledge2();
void set_para2();
void start_cycle2();
void start_cycle22();
void test_mode2();
void main()
{
    in2();
    lcdcmd2(0X38);
    lcdcmd2(0X0C);
    lcdcmd2(0X01);
    strwrt2(0x80,"  ------ ");              //welcome message for some time
    strwrt2(0xc0,"   -----   ");
    msdelay2(500);
    strwrt2(0x80,"  Give signal     ");
    clearb2();
    while(1)
    {
        if(start == 0)
        {
            set_para2();
        }
        if(l1 == 0 )
 
        {
            
            start_cycle2();
 
    
        }
    
    }
 
 
}
void set_para2()
{
    strwrt2(0x80,"Set R2 ON Time  ");
    clearb2();
    numdis2(0xC0,timer12);
    timer12 = newvalue2*10;
    high2 = timer12 >> 8;
    low2 = timer12;
    send_to_mem2(0x00, high2);
    msdelay2(10);
    send_to_mem2(0x01, low2);
    msdelay2(300);
 
            
    strwrt2(0x80," Test Mode       ");
    clearb2();
    while(enter)
    {
        if(start == 0)
        {
            test_mode2();
            break;  
        }
    }
 
    v2 = 1;
 
    strwrt2(0x80," Give Signal    ");
    clearb2();
    while(start == 0);  
    msdelay2(20);
}
void start_cycle2()
{
 
     v2 = 0;
     strwrt2(0x80,"R2 ON          ");
     msdelay2(200);
    if (l1 == 1 )
    {
    start_cycle22();
    }
 
}
void start_cycle22()
{
     float temp2;
    strwrt2(0x80,"R2 ON T- ");
    clearb2();
    tik2 = 0;
    TH1 = 0x5D;
    TL1 = 0x3D;
    dummytimer2 = timer12/10.0;
    temp2 = dummytimer2;
  //    v1 = 0;
    TR1 = 1;
    num2(0x89,dummytimer2);
    while(dummytimer2>=0)           
    {
        if(temp2 !=dummytimer2)
        {
            num2(0x89,dummytimer2);
            temp2 = dummytimer2;    
        }
            }
    TR1 = 0;
    v2 = 1;
 
 
       
      //v2 = 1;
      strwrt2(0x80," Give Signal     ");
        clearb2();
 
    }               
 
void test_mode2()
{
    unsigned int i = 0;
    strwrt2(0x80,"                ");   
    clearb2();
    strwrt2(0x80,"V1=Off");
//  strwrt(0x88,"V2=Off");
//  strwrt(0xc0,"V2=Off");
//  strwrt(0xc8,"V3=Off");
    while(start == 0);
    msdelay2(20);
    while(1)
    {
        if(start == 0)  
        {
 
            v2=0;
        //  motor = 0;
            strwrt2(0x80,"V1=On ");
            msdelay2(100);
            while(start == 0)
            {
                while(enter == 0)
                {
                    i++;
                    msdelay2(1);
                    if(i == 500)
                    {
                        return;
                    }
                }
                i = 0;
            }
             v2=1;
        //  motor = 1;
            strwrt2(0x80,"V1=Off");
            msdelay2(20);
        }
        
 
        }        
 
}
void in2()
{
    //P3 = 0xF0;
    l1 =1;
//  l2=1;
//  l3=1;
    P2 = 0X00;
//  P1 = 0X1F;
 
//  l4 = 1;
//  l5_start =1;
//  l6_stop = 1;
 
    P0 = 0X00;
    TMOD = 0X11;
//  IE = 0X82;
    IE = 0x88;
 
 
 
 
    TR1 = 0;
    high2 = get_from_mem2(0x00);
    low2 = get_from_mem2(0x01);
    timer12=(high2<<8)|low2;
 
}
 
void msdelay2(unsigned int value)
{
    unsigned int i,j,temp;
    temp = value;
    for(i=0; i<=temp; i++)
        for(j=0; j<=200; j++);
}
void lcddata2(unsigned char value)
{
    wait_lcd2();
    ldata = value;
    rs = 1;
    rw = 0;
    en = 1;
    en = 0;
}
void lcdcmd2(unsigned char value)
{
    wait_lcd2();
    ldata= value;
    rs = 0;
    rw = 0;
    en = 1;
    en = 0;
}
 
void wait_lcd2()
{
    en = 0;
    d7 = 1;
    rs = 0;
    rw = 1;
    while(d7 == 1)
    {
        en = 0;
        en = 1;
    }
}
void numdis2(unsigned char value, unsigned int num)
{
    unsigned char i;
    unsigned char d[4];
    sprintf(d, "%4d", num);
    for(i = 0; i < 4; i++)
    {
        if(d[i] <= 48)
            d[i] = 48;
    }
    lcdcmd2(value);
    d[0] = d[1];           //start formating 
    lcddata2(d[0]);
    d[1] = d[2];
    lcddata2(d[1]);
    d[2] = 46;
    lcddata2(d[2]);
    lcddata2(d[3]);       //finish reformat
    lcdcmd2(value);
    lcdcmd2(0x0F);
    for(i = 0; i < strlen(d); i++)
    {
        while(dec== 1 && d[i] != 46)
        {
            if(inc == 0 && d[i] != 46)
            {
                if(d[i] == 57)
                {
                    d[i] = 47;
                }
                d[i]++;
                lcddata2(d[i]);
                lcdcmd2(0x10);
                msdelay2(300);
            }       
        }
        msdelay2(300);
        lcdcmd2(0x14);
    }
    newvalue2 = atof (d);
}
void strwrt2(unsigned char value, unsigned char *str)
{
    unsigned int i;
    lcdcmd2(value);
    for(i = 0; i < strlen(str); i++)
    {
        lcddata2(str[i]);
    }
}
void num2(unsigned char value, float num)
{
    unsigned char c[4];
    char i;
    lcdcmd2(0x0C);
    lcdcmd2(value);
    sprintf(c, "%4f", num);
    for(i = 0; i < 4; i++)
    {
        if(num <= 10)
            c[3] = 48;
        lcddata2(c[i]);
    }
}
void numwhole2(unsigned char value, unsigned int num)
{
    unsigned char c[4];
    char i;
    lcdcmd2(0x0C);
    lcdcmd2(value);
    sprintf(c, "%4d", num);
    for(i = 0; i < 4; i++)
    {
        lcddata2(c[i]);
    }
}
void clearb2()
{
    strwrt2(0xc0, "                ");  
}
/* eeprom functions */
 void send_to_mem2(char s_address, char s_data)
 {
   
    start_s_eeprom2();             // sending start condition to eeprom 
    send_byte_s_eeprom2(0XA0);     // A0 = 10100000 = sending device address word for write
    acknowledge2();
    send_byte_s_eeprom2(s_address); // sending data address
    acknowledge2();
    send_byte_s_eeprom2(s_data);   // sending data 
    acknowledge2();
    stop_s_eeprom2();              // sending stop condition to eeprom
   acknowledge2();
   return;  
 }
 unsigned int get_from_mem2(char s_address)
 {
    char i = 0;
//-------dummy write seq----+ word address------------------------------------
    start_s_eeprom2();             // sending start condition to eeprom 
    send_byte_s_eeprom2(0XA0);     // sending A0 = 10100000 = device address word for write
    acknowledge2();
    send_byte_s_eeprom2(s_address); // sending data address
    acknowledge2();
//----------------dummy over----------------------------------------------------
    start_s_eeprom2();
    send_byte_s_eeprom2(0XA1);     // sending A1 =10100001 = device adress word for read
    acknowledge2();
    i = get_byte_s_eeprom2(); // sending data 
    acknowledge2();
    stop_s_eeprom2();              // sending stop condition to eeprom
    acknowledge2();
    return(i); 
 }
 void send_byte_s_eeprom2(char s_byte)
 {
    char temp2 = s_byte;
    char i ;
    for(i = 7 ; i >= 0 ; i--)
    {
        temp2 = s_byte;
        temp2 = temp2 >> i;
        temp2 = temp2 & 0X01;
        if(temp2 == 0)
            sda =   0;
        else
            sda =   1;
            sclk   =   1;
            wait2();
            sclk   =   0; 
    }
   return;
 }
 char get_byte_s_eeprom2()
 {
    char temp2, temp_h2, i;
    temp2=0;
    temp_h2=1;   
    sda=1;    // making SDA as input pin for microcontroller
    sclk=0;
    for(i = 7; i >=0 ; i--)
    {
     sclk = 1;
      if(sda == 1)
        {
            temp2 = temp2 | temp_h2<<i ;                      
        }
        wait2();
      sclk = 0;
    }
    sclk = 0;
    return(temp2);
 }
 void start_s_eeprom2()
 {
    sda=1;
    sclk=1;
    wait2();
   sda=0;
   sclk=0;  
   return; 
 }
 void stop_s_eeprom2()
 {
    sda=0;
    sclk=1;
    wait2();
    sda=1;
    sclk=0;
   return;   
 }
 void acknowledge2()
 {
   sclk=1;
   wait2();
   sclk=0;
   return;
 }
 void wait2()
 {
    char i;
    for(i=0;i<=20;i++)
      i++;
    return;
 }
void timer1(void) interrupt 3
{
    TH1 = 0x5D;
    TL1 = 0x3D;
    TR1 = 1;
    tik2++;
    if(tik2 == 4)
    {
        dummytimer2 = dummytimer2-0.1;
        tik2 = 0;
    }

 
Last edited by a moderator:

There are a lot of unknowns, here. Try verifying separately that your signal is reliably being detected, by triggering something besides Timer1, like pulling an I/O port high, or triggering an LED when the signal is detected. You may have a problem with detecting a signal. Once you've verified that your microcontroller is truly detecting a signal, then you can move on. After that, verify separately that you can control Timer1 reliably.

The problem is not that "Timer1 cannot be triggered when a signal is detected"--your problem is either that you are not reliably detecting a signal, or that you have not written the correct code to trigger Timer1.
 

Dear Bro.

i had already tested for timer0, its working ok.
But i think that for timer1 there is mistake in interrupt or loading of data. I have to use both timer0 and 1 perallaly thats y i required it. I am waiting for your replay.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top