Ⅰ 用單片機進行廣告燈的控制
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;
}