Interrupt waiting Time with Keil
Sun Oct 31 2010, 08:55 pm
u just insert a break point in interrupt function so when interrupt occur u check the time
is it 50ms or not
is it 50ms or not
Mon Nov 01 2010, 07:44 am
hi all. Hehe i dont really understand this function when i should use this type of operator "~"
example. clock=~clock;
example. clock=~clock;
Mon Nov 01 2010, 08:00 am
Hi joepotter, take a look with this example of interrupt with timer. It shifts to the right every 1 sec.
shift left and right(with
timer)
shift left and right(with
timer)
#include<reg51.H> unsigned char cnt=0; unsigned char x; void timer0() interrupt 1 { TR0=0; TH0=0x3c; TL0=0xb0; cnt++; if(cnt==20) { x=P0&0x0f; x=x> > 1; if(x==0) { x=0x08; } P0=0xf0&P0; P0=P0|x; cnt=0; } TR0=1; } void left() interrupt 0 { char i; i=P0&0xf0; P0=P0&0x0f; i=i<<1; if(i==0) i=0x10; P0=P0|i; } void main() { P3=0x0c; P0=0x18; EA=1; EX0=1; ET0=1; IT0=1; TMOD=TMOD&0x0f; TMOD=TMOD|0x01; TL0=0xb0; TH0=0x3c; TR0=1; while(1) { PCON=PCON|0x01; } }
[ Edited Mon Nov 01 2010, 08:30 am ]
Mon Nov 01 2010, 09:07 am
hi romel_emperado
"~" means invert the pin status or invert the bis of variable too
in other words it is a not gate operation
i code it will invert the pin status after each 50 ms hence generating a clock
i dont really understand this function when i should use this type of operator "~" example. clock=~clock;
"~" means invert the pin status or invert the bis of variable too
in other words it is a not gate operation
i code it will invert the pin status after each 50 ms hence generating a clock
Mon Nov 01 2010, 01:34 pm
in your example y it needs to invert? in short that operator is like an inverter or NOT GATE
#include <reg51.h> sbit clock = P1^0; void timer0 (void) interrupt 1 // interrupt function { clock=~clock; TH0=0X4B; TL0=0xFD; } void main (void) { TMOD=0X01; // @ 11.0592MHz TH0=0X4B; // 50 ms delay TL0=0xFD; TR0=1; IE=0X82; // enable timer0 interrupt along with global interrupt enable while(1);
Mon Nov 01 2010, 01:58 pm
i just create a clock on pin p1.0 so i need if
let say
this is a code for same clock pin
if(clcok==1)
clock=0;
else
clcok=1;
now these 4 lines can be replace by only one
clcok=~clock;
let say
this is a code for same clock pin
if(clcok==1)
clock=0;
else
clcok=1;
now these 4 lines can be replace by only one
clcok=~clock;
Mon Nov 01 2010, 02:11 pm
ah okay in short you choosed the shortest way... now i learned new from you majoka.. thanks again
[ Edited Mon Nov 01 2010, 02:16 pm ]
Mon Nov 01 2010, 02:28 pm
hi
when ur using c always find short cuts in written form that is easy approach
when ur using c always find short cuts in written form that is easy approach
Tue Nov 02 2010, 03:55 am
if clock is dependent on a flag which is updated smwhere else..then.. you can do like this too..
clock = flag ? 1 : 0; //if its inverted logic then.. clock = (!flag) ? 1 : 0;
romel_emperado like this.
Powered by e107 Forum System