【发布时间】:2015-03-11 16:50:38
【问题描述】:
void main(void)
{
unsigned char in_char;
int flag=1,j,i;
int count, d = 0 ;
char s[4]="",p;
ithul();
LCD_res();
init_lcd()
;print_lcd(1,"The Project");//Printing command.
;print_lcd(2,"of Me:");//Printing command.
for(i=0; i<20; i++){delay(1000);delay(1000);delay(1000);}
for(i=0; i<20; i++){delay(1000);delay(1000);delay(1000);}
while(1)
{
count = 0;
loop1 : if(P3_0 == 1){
goto loop1;
}
//Running '1'
loop2 : if(P3_0 == 0){
goto loop2;
}
//Running '0'
while(P3_0 == 1){
count ++;
}
init_lcd()
;print_lcd(1,"Done Counting!");//Printing command.
for(i=0; i<1; i++){delay(1000);delay(1000);delay(1000);}
;print_lcd(2," - L/H...");//Printing command.
for(i=0; i<20; i++){delay(1000);delay(1000);delay(1000);}
for(i=0; i<20; i++){delay(1000);delay(1000);delay(1000);}
for(i=0; i<20; i++){delay(1000);delay(1000);delay(1000);}
;print_lcd(2,itoa(count/200));//Printing command.
for(i=0; i<20; i++){delay(1000);delay(1000);delay(1000);}
for(i=0; i<20; i++){delay(1000);delay(1000);delay(1000);}
}
}
这是我的代码。它的作用是从端口获取频率,读取并打印到 LCD。
它的作品!但是大约 2 分钟后,LCD 变得像“asda68!#123646$#$^%&*(dfas”那种垃圾!。
如何刷新 8051 微控制器使其不会发疯? 我听说过一些关于“新鲜”“免费”“闪光”命令的信息,但我真的不知道它是什么或如何使用它。所以..请帮忙!
【问题讨论】:
-
为什么每个打印行的开头都有分号?
free(count)不会做任何事情,除非可能会破坏一些内存,因为count不是指针。 -
你已经声明了
int count;那么free(count);应该做什么? -
抱歉,我删除了。
-
在任何情况下,您都应该使用定时器寄存器(最好使用边沿触发捕获)来测量频率,而不是软件循环。
-
不应该
itoa()带一个字符串参数吗?