sherryliu
Member level 1
- Joined
- Jan 17, 2011
- Messages
- 32
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,288
- Activity points
- 1,535
Hi guys,i want to modified code to show blink led difference,how to optimized the code.when i click one show one way and click again show other way.
#include <reg51.h>
#include<intrins.h>
unsigned char tmod=0;
unsigned char i ,j,tmp;
void delay_1ms(void)
{
unsigned int i;
for (i=1;i<(unsigned int)(1144-2);i++);
}
void delay_ms(unsigned int n)
{
unsigned int i=0;
while(i<n)
{
delay_1ms();
i++;
}
}
void main(void)
{
ET0=1;
ET1=1;
EX0=1;
EX1=1;
EA=1;
while(1)
P0=0x00;
}
void int0(void) interrupt 0
{
switch(tmod)
{
case 0:
tmp=0x01;
for(j=8; j>0; j--)
{
P0=~tmp;
delay_ms(50);
tmp =tmp<<1;
}
break;
case 1:
tmp=0x80;
for(j=8; j>0; j--)
{
P0=~tmp;
delay_ms(50);
tmp = tmp>>1;
}
break;
case 2:
break;
}
tmod+=1;
if(tmod==2)tmod=0;
}
#include <reg51.h>
#include<intrins.h>
unsigned char tmod=0;
unsigned char i ,j,tmp;
void delay_1ms(void)
{
unsigned int i;
for (i=1;i<(unsigned int)(1144-2);i++);
}
void delay_ms(unsigned int n)
{
unsigned int i=0;
while(i<n)
{
delay_1ms();
i++;
}
}
void main(void)
{
ET0=1;
ET1=1;
EX0=1;
EX1=1;
EA=1;
while(1)
P0=0x00;
}
void int0(void) interrupt 0
{
switch(tmod)
{
case 0:
tmp=0x01;
for(j=8; j>0; j--)
{
P0=~tmp;
delay_ms(50);
tmp =tmp<<1;
}
break;
case 1:
tmp=0x80;
for(j=8; j>0; j--)
{
P0=~tmp;
delay_ms(50);
tmp = tmp>>1;
}
break;
case 2:
break;
}
tmod+=1;
if(tmod==2)tmod=0;
}