顯示具有 8051 標籤的文章。 顯示所有文章
顯示具有 8051 標籤的文章。 顯示所有文章

星期一, 10月 19, 2009

8051 w2


#pragma oe db pw(80) SM SB CD
#include
#include "Delay.h"
main(){
int num = 0;
char State=0;
P2 =0x3f;

for(;num<6;){
Delay1s();
if(State == 1){
P2 <<= 1;
P2 |=0x01;
}
if(State == 0){
P2 >>= 1;
P2 |=0x80;
}

if((P2&0xc0)==0){//0011 1111 + 1100 0000 =0
State= 0;
num++;
}
if((P2&0x03)==0){
State= 1;
num++;
}
}

for(;;);
}

8051 w2


#pragma oe db pw(80) SM SB CD
#include
#include "Delay.h"
main(){
int num = 0;
char State=0;
P2 =0x3f;

for(;num<6;){
Delay1s();
if(State == 1){
P2 <<= 1;
P2 |=0x01;
}
if(State == 0){
P2 >>= 1;
P2 |=0x80;
}

if((P2&0xc0)==0){//0011 1111 + 1100 0000 =0
State= 0;
num++;
}
if((P2&0x03)==0){
State= 1;
num++;
}
}

for(;;);
}

8051 led2


#pragma oe db pw(80) SM SB CD
#include
void Delay1s(void){ //時間延遲一秒的函數
ACC = 5;
F0 = 1;
F0 = 1;
F0 = 1;
}
main(){
int num = 0; //宣告用來表示次數的變數
char State=0; //宣告檢測右邊和左邊的變數
P0 =0xc0; //初始設定左邊2個點燈是亮的
for(;num<6;){ //來回跑3次的設定
Delay1s(); //時間暫停一秒
if(State == 0) P0 >>= 1; //當電燈到達左邊2個發光時,開始向右邊跑
if(State == 1) P0 <<= 1; //當電燈到達右邊2個發光時,開始向左邊跑
if((P0&0x3f)==0){ //當電燈到達左邊時
State= 0; //檢測變數會改變為 左
num++; //開始算一次
}
if((P0&0xfc)==0){ //當電燈到達右邊
State= 1; //檢測變數會改變為 右
num++; //開始算一次
}
}
for(;;);//讓程式進入無限回圈
}

星期二, 10月 13, 2009

8051 led


#pragma oe db pw(80) SM SB CD
#include
#include "Delay.h"
code tbl1[]= { 0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf } ;
int num= 0;

int main()
{
char i ;
int id = 0;
/*P0 =0x01;*/
P0 =0xc0;
/*P0 =0x80;*/

for(num = 0;num<=6;){
Delay100ms() ;
P3 = num;
if((P0&0x3f) == 0){ /*0x01*/
num++;
id = 1;
}
if((P0&0xfc) == 0){ /*0x80*/
num++;
id = 0;
}
if(id == 0){
P0 <<=1 ;
}else{
if(num<6) P0 >>=1 ;
}
}
Delay1s() ;
Delay1s() ;
Delay1s() ;
Delay1s() ;

/*P0 >>=1;*/
/*P0=tbl1[1];*/
/*
for(;;) {
for(i = 0 ; i < 14 ; i++ ){
P0=tbl1[i] ;
Delay100ms() ;
}
}
*/
return 0;

}