Ⅰ 用单片机进行广告灯的控制
public int testException_finally(){
int x;
try {
x = 1;
//int y = 1/0; //放开此处,出现ArithmeticException。
/*//注释掉 int y = 1/0;处,放开此处,出现NullPointerException
String str = null;
str.substring(0);
*/
return x;
} catch (ArithmeticException e) {
x =2;
return x;
} finally{
x = 3;
}
Ⅱ 单片机课程设计 广告灯 求C语言的
#include<reg52.h>
void delayMs(unsigned char m); //函数声明void delayUs2x(unsigned char t);
void delay1s(unsigned int r);
/*------------------------------------------------
主函数
------------------------------------------------*/
void main (void)
{
unsigned char i;
unsigned char temp;//临时转换变量
while (1)
{
for(i=0;i<4;i++) //for循环,执行4次
{ P1=0xff; //LED全灭
delay1s(1);
P1=0x00; //LED全亮
delay1s(1);
}
temp=0xfc; //11111100
P1=temp;
for(i=0;i<7;i++) //for循环,执行7次
{
delay1s(1); //调用1s延时程序
temp<<=1; //移位
temp=temp|0x01;
}
}}
/*------------------------------------------------
μs级延时函数
------------------------------------------------*/
void delayUs2x(unsigned char t)
{
while(--t);
}
/*------------------------------------------------
mS级延时函数
------------------------------------------------*/
void delayMs(unsigned char m)
{
while(m--)
{
//大致延时1mS
delayUs2x(245);
delayUs2x(245);
}
}
/*------------------------------------------------
s级延时函数
-------------------------------------------------*/
void delay1s(unsigned int r)
{
while(r--)
{
//大致延时1s
delayMs(1000);
delayMs(1000);
}
}
Ⅲ 单片机控制广告灯课题设计程序
#include<reg51.h>
unsigned char time=0;
void delay(unsigned long w)
{
while(w--);
}
void zuoxunhuan()
{
unsigned char C;
for(C=0x80;C!=0;C>>=1) //左移
{
P1=C;
delay(30000);
}
}
void youxunhuan()
{
unsigned char C;
for(C=0x01;C!=0;C<<=1) //右移
{
P1=C;
delay(30000);
}
}
void zengti() //递增
{
unsigned int C;
for(C=0xFE;C!=0;C<<=1)
{
P1=~C;
delay(30000);
}
}
void jiaoti() //交替
{
P1=0x55;
delay(30000);
P1=0xaa;
delay(30000);
}
void init_init()
{
EX0=1;
EA=1;
}
void into_into() interrupt 0 //P3.2外接一个按键底电瓶有效切换程序
{
if((time+=1)==5) time=0;
delay(400000);
}
void main()
{
init_init();
while(1)
{
if(time==1) zuoxunhuan();
if(time==2) youxunhuan();
if(time==3) zengti();
if(time==4) jiaoti();
if(time==0)
{
zuoxunhuan();
youxunhuan();
zengti();
jiaoti();
}
}
}
Ⅳ 单片机广告灯的设计C语言程序<分数不多 但求大神告知 好人一生平安>
#include<reg51.h>
#define uchar unsigned char
uchar ledt[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uchar ledi[]={0xfc,0xf9,0xf3,0xe7,0xcf,0x9f,0x3f,0x7e);
uchar nt=0,ni=0;
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
switch(nt)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
P1=ledt[nt];break;
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
p1=ledt[14-nt];break;
case 15:
P1=0x00;break;
case 16:
P1=0xff;break;
default:
nt=0;break;
}
nt++;
}
void ext0() interrupt 0
{
switch(ni)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
P1=ledt[ni];break;
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
P1=ledt[14-ni];break;
case 15:
P1=0xff;break;
case 16:
P1=0x00;break;
default:
ni=0;break;
}
}
void delay(uchar a)
{
uchar i,j;
for(i=0;i<a;i++)
for(j=0;j<120;j++);
}
main()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=1;
EX0=1;
IT0=0;
EA=1;
TR0=1;
while(1)
{
while(P3_2)
{
TR0=0;
delay(50);
ni++;
}
TR0=1;
}