Discussion in "8051 Discussion Forum" started by    joepotter    Oct 29, 2010.
Sun Oct 31 2010, 08:55 pm
#11
u just insert a break point in interrupt function so when interrupt occur u check the time
is it 50ms or not
Mon Nov 01 2010, 07:44 am
#12
hi all. Hehe i dont really understand this function when i should use this type of operator "~"

example. clock=~clock;
Mon Nov 01 2010, 08:00 am
#13
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)
#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
#14
hi romel_emperado

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
#15
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
#16
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;
Mon Nov 01 2010, 02:11 pm
#17
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
#18
hi
when ur using c always find short cuts in written form that is easy approach
Tue Nov 02 2010, 03:55 am
#19
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.
Tue Nov 02 2010, 10:28 am
#20
yes exactly ajay

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm
Bernardwarge
Tue Mar 26 2024, 11:15 am