32位摇摇棒图纸和程序

更新时间:2023-09-17 03:57:01 阅读量: 高中教育 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

#include

/*********外猘部?接?口ò定¨义?**********/ #define uchar unsigned char

#define uint unsigned int //宏ê定¨义? #define out P1

//数簓据Y输?出?端?口ò

ED ED ED ED

sbit led1=P3^0; //第台?sbit led2=P3^1; //第台?sbit led3=P3^3; //第台?sbit led4=P3^4; //第台?sbit p3_2=P3^2;

uchar KY,num; //KY作痢 用?在ò后?面?说μ明e uchar BUFF;

//缓o存?

/*********全?局?变?量?定¨义?**********/ unsigned long int TimeCount=0; unsigned int DelayN=80,

unsigned char key,keyy;

//延?时骸 临ⅷ 时骸 计?数簓

DelayTime=80; //每?次?延?时骸 的?周ó期ò个?数簓

sbit key1=P3^5; //按恪 键ó输?入?

/**********************************************/ void delay(unsigned char n); void DelayMs(void);

/*******************************************/

unsigned char code text0[]={

0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,/*\\

0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x00,0xB7,0xBB,0xB7,0xBB,0xB3,0xBB,0xB4,0xBB,0xB5,0xBB,0xB7,0xBB,0xB7,0xBB,0xB7,0xBB,0x07,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,/*\自?\

0xBF,0xBF,0xBE,0xDF,0x39,0xE0,0xFF,0xDF,0xEF,0xBF,0xEF,0xBF,0x6D,0xB0,0x6D,0xB7,0x6D,0xB7,0x01,0xB7,0x6E,0xB7,0x6E,0xB7,0x6E,0xB0,0xEF,0xBF,0xEF,0xBF,0xFF,0xFF,/*\适酣?,2*/

0xFF,0xBF,0xFF,0xC7,0x03,0xF8,0xBB,0xDF,0x7B,0xDF,0xFB,0xD0,0xEB,0xDB,0xDA,0xDF,0x39,0xDC,0x7B,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F,0xFE,0xBF,0xFD,0xBF,0xE3,0xBF,0xF7,0xBF,0xFF,0xBF,0xBF,0x87,0x7F,0xFF,0xFF,0xF8,0xFF,0xFD,0xFF,0xFF,/*\心?\ };

unsigned char code text2[]={

0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF9,0xFF,0xFF,0x9F,0xF9,0xFF,0xFF,0x9F,0xF9,0xFF,0xFF,0x9F,0x01,0x00,0x00,0x80,0x01,0x00,0x00,0x80,0xF9,0xFF,0xFF,0x9F,

0xF9,0xFF,0xFF,0x9F,0xF9,0xFF,0xFF,0x9F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0x01,0xFE,0xFF,

0x7F,0x00,0xF8,0xFF,0x3F,0x00,0xF0,0xFF,0x1F,0x00,0xE0,0xFF,0x0F,0x00,0xC0,0xFF,0x07,0x00,0x80,0xFF,0x03,0x00,0x00,0xFF,0x03,0x00,0x00,0xFF,0x03,0x00,0x00,0xFE,

0x03,0x00,0x00,0xFC,0x03,0x00,0x00,0xF8,0x07,0x00,0x00,0xF0,0x0F,0x00,0x00,0xE0,0x1F,0x00,0x00,0xE0,0x3F,0x00,0x00,0xC0,0x3F,0x00,0x00,0x80,0x1F,0x00,0x00,0xC0,

0x0F,0x00,0x00,0xE0,0x07,0x00,0x00,0xF0,0x03,0x00,0x00,0xF8,0x03,0x00,0x00,0xFC,0x03,0x00,0x00,0xFE,0x03,0x00,0x00,0xFF,0x07,0x00,0x80,0xFF,0x0F,0x00,0xC0,0xFF,

0x1F,0x00,0xE0,0xFF,0x3F,0x00,0xE0,0xFF,0xFF,0x00,0xF8,0xFF,0xFF,0x01,0xFC,0xFF,0xFF,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,

0x07,0x00,0x00,0xE0,0x07,0x00,0x00,0xC0,0x07,0x00,0x00,0xC0,0xFF,0xFF,0xFF,0xC7,0xFF,0xFF,0xFF,0xCF,0xFF,0xFF,0xFF,0xCF,0xFF,0xFF,0xFF,0xCF,0xFF,0xFF,0xFF,0xCF,

0xFF,0xFF,0xFF,0xCF,0xFF,0xFF,0xFF,0xCF,0xFF,0xFF,0xFF,0xCF,0xFF,0xFF,0xFF,0xC7,0x07,0x00,0x00,0xC0,0x07,0x00,0x00,0xC0,0x07,0x00,0x00,0xE0,0xFF,0xFF,0xFF,0xFF,/*\未′命ó名?文?件t\ };

/***********n{

s)?延?时骸 子哩 程ì序?***************/

void DelayUs(uint N)

?,7*/ ?,6*/

uint x;

for(x=0; x<=N;x++); }

/******************************************/ void main() {

AUXR=0x80; CLK_DIV=1;

EX0=1; //开a放?外猘部?中D断?0

IT0=1; //中D断?0为a边?沿?触洌 发ぁ 方?式? IP=0x02; //设Θ 置?中D断?优?先è级? TMOD=0x02; //定¨时骸 器e0方?式?2,?8位?重?装痢 载? TH0=0x80; //设Θ 定¨定¨时骸 器e初?值μ TL0=0x80;

KY=0; EA=1;

//开a放?中D断?

ET0=1; //开a放?定¨时骸 器e0中D断?

TR0=1; //启?动ˉ定¨时骸 器e0,?开a始?计?时骸?/ key=0; //初?始?化ˉ显?示?第台 一?组哩 文?字? keyy=0; P1M0=0x55;

//0101 0101 /P1.0 P1 .2 P1.4 P1.6推?

输?出?

P1M1=0xAA;

while(1){//等台 待鋣中D断?

if(key1==0){ //有瓺键ó按恪 下? DelayUs(50); if(key1==0){ key++;

//更ó换?下?一?幅え 图?片?

if(key>2) key=0; //图?片?循-环·显?示? 根?据Y显?示?的?组哩 数簓来ぁ这a里?有瓺9组哩?所?以?就í要癮keyy>9

while(key1==0); //等台 待鋣按恪 键ó释酣 放?

} } if(num>10) //每?中D断?10次?切D换?

{ keyy++; num=0;

}

if(keyy>2)keyy=0; //图?片?循-环·显?示? 根?据Y显?示?的?组哩 数簓来ぁ这a里?有瓺9组哩?所?以?就í要癮keyy>9 }

}

定¨义? 定¨义? /*********文?字?显?示?子哩 程ì序?**********/

void display_word(unsigned char code *text) {

unsigned char i,j=2; //j为a图?片?起e始?位?置? 3 为a第台?个?开a始?

是?图?片? 如?果?要癮显?示?高?时骸?2的?大洙 字? 也?属?

DelayUs(6400);

for(i=0;i<64;i++) {

P3M0=0x00;

//0000 0000 //P3.0推?

高?阻哩 P3M1=0x1B; if((key>=j)||(keyy>=j)) BUFF=(*(text+i*4+3)); else

BUFF=(*(text+128+i*2+1));

led4=0; P1=~BUFF>>1;

P3M0=0x10;

//0001 0000 //P3.4推?

高?阻哩

P3M1=0x0B; //0000 1011 delay(1);

P3M0=0x00;

//0000 0000 //P3.0推?高?阻哩

P3M1=0x1B;

//0001 1011

led4=1;

P1=BUFF; //01010101 1357

P3M0=0x10;

//0001 0000 //P3.4推?

高?阻哩

P3M1=0x0B; //0000 1011 delay(1);

P3M0=0x00;

//0000 0000 //P3.0推?高?阻哩

P3M1=0x1B;

//0001 1011

if((key>=j)||(keyy>=j)) BUFF=(*(text+i*4+2)); else

BUFF=(*(text+128+i*2)); led3=0; P1=~BUFF>>1;

P3M0=0x08;

//0000 1000 //P3.3推?

高?阻哩

图?片?格?式?

输?出? P3 .1 P3.3 P3.4输?入?

输?出? P3 .0 P3.3 P3.1输?入?

输?出? P3 .1 P3.3 P3.4输?入?

输?出? P3 .0 P3.3 P3.1输?入?

输?出? P3 .1 P3.3 P3.4输?入?

输?出? P3 .0 P3.1 P3.4输?入?

P3M1=0x13; //0001 0011 delay(1);

P3M0=0x00;

//0000 0000 //P3.0推?高?阻哩

P3M1=0x1B;

//0001 1011

led3=1;

P1=BUFF; //01010101 1357

P3M0=0x08;

//0000 1000 //P3.3推?

高?阻哩

P3M1=0x13; //0001 0011 delay(1);

P3M0=0x00;

//0000 0000 //P3.0推?

高?阻哩

P3M1=0x1B; if((key>=j)||(keyy>=j)) BUFF=(*(text+i*4+1)); else

BUFF=(*(text+i*2+1)); led2=0; P1=~BUFF>>1;

P3M0=0x02;

//0000 0010 //P3.1推?高?阻哩

P3M1=0x19; //0001 1001

delay(1);

P3M0=0x00;

//0000 0000 //P3.0推?高?阻哩

P3M1=0x1B;

//0001 1011

led2=1;

P1=BUFF; //01010101 1357

P3M0=0x02;

//0000 0010 //P3.1推?高?阻哩

P3M1=0x19; //0001 1001

delay(1);

P3M0=0x00;

//0000 0000 //P3.0推?高?阻哩

P3M1=0x1B;

//0001

if((key>=j)||(keyy>=j)) BUFF=(*(text+i*4)); else

BUFF=(*(text+i*2)); led1=0; P1=~BUFF>>1;

P3M0=0x01;

//0000 0001 //P3.0推?

高?阻哩

输?出? P3 .1 P3.3 P3.4输?入?

输?出? P3 .0 P3.1 P3.4输?入?

输?出? P3 .1 P3.3 P3.4输?入?

输?出? P3 .0 P3.3 P3.4输?入?

输?出? P3 .1 P3.3 P3.4输?入? 输?出? P3 .0 P3.3 P3.4输?入?

输?出? P3 .1 P3.3 P3.4输?入? 输?出? P3 .1 P3.3 P3.4输?入?

} }

P3M1=0x1A;

delay(1);

P3M0=0x00;

//0001 1010

//0000 0000 //P3.0推?//0001 1011

//0000 0001 //P3.0推?//0001 1010

输?出? P3 .1 P3.3 P3.4输?入? 输?出? P3 .1 P3.3 P3.4输?入?

高?阻哩

P3M1=0x1B;

led1=1; P3M0=0x01;

P1=BUFF; //01010101 1357

高?阻哩

P3M1=0x1A;

delay(1);

/*********显?示?内ò容╕选?择?子哩 程ì序?**********/ void display(unsigned char t) {

keyy=0; switch (t){

//

过y按恪 键ó选?择?显?示?内ò容╕

case 0: {display_word(text0);}break; case 1: {display_word(text1);}break; case 2: {display_word(text2);}break; case 3: {display_word(text3);}break; case 4: {display_word(text4);}break; case 5: {display_word(text5);}break; case 6: {display_word(text6);}break; case 7: {display_word(text7);}break;

// // // // //

// case 8: {display_word(text8);}break; // case 9: {display_word(text9);}break; // case 10:{display_word(text10);}break;

//default:{display_word(text1);} }}

/*****************************************/ void display1(unsigned char y) {

switch (y){

//

过y按恪 键ó选?择?显?示?内ò容╕

case 0: {display_word(text0);}break; case 1: {display_word(text1);}break; case 2: {display_word(text2);}break; case 3: {display_word(text3);}break; case 4: {display_word(text4);}break; case 5: {display_word(text5);}break; case 6: {display_word(text6);}break; case 7: {display_word(text7);}break;

// // // // //

// case 8: {display_word(text8);}break; // case 9: {display_word(text9);}break; // case 10:{display_word(text10);}break;

} }

/***************************************/ /*********延?时骸 子哩 程ì序?**********/ void delay(unsigned char n) { }

/*********中D断?子哩 程ì序?**********/ void int0() interrupt 0 { KY=~KY; if(KY==0) { } }

void timer0() interrupt 1 { }

TimeCount++; if (DelayN!=0) DelayN--;

//定¨时骸 器e0中D断?子哩 程ì序?

DelayTime=TimeCount/1580;

TimeCount=0; //延?时骸 周ó期ò计?数簓清?零? if(key==0) { num++;

display1(keyy); //根?据Y按恪 键ó选?择?循-环·显?示?文?字? } else {

display(key); //根?据Y按恪 键ó选?择?循-环·显?示?文?字? }

//使?用?外猘部?中D断?0

for(;n>0;n--){ }

DelayN=DelayTime; while (DelayN);

//-------------------------------------------------------------------------------- //新一代 1T 8051系列 单片机内核特殊功能寄存器 C51 Core SFRs

// 7 6 5 4 3 2 1 0 Reset Value sfr ACC = 0xE0; //Accumulator 0000,0000 sfr B = 0xF0; //B Register 0000,0000

sfr PSW = 0xD0; //Program Status Word CY AC F0 RS1 RS0 OV F1 P 0000,0000

//----------------------------------- sbit CY = PSW^7; sbit AC = PSW^6; sbit F0 = PSW^5; sbit RS1 = PSW^4; sbit RS0 = PSW^3; sbit OV = PSW^2; sbit P = PSW^0;

//----------------------------------- sfr SP = 0x81; //Stack Pointer 0000,0111 sfr DPL = 0x82; //Data Pointer Low Byte 0000,0000 sfr DPH = 0x83; //Data Pointer High Byte 0000,0000

//-------------------------------------------------------------------------------- //新一代 1T 8051系列 单片机系统管理特殊功能寄存器

// 7 6 5 4 3 2 1 0 Reset Value

sfr PCON = 0x87; //Power Control SMOD SMOD0 LVDF POF GF1 GF0 PD IDL 0001,0000

// 7 6 5 4 3 2 1 0 Reset Value

sfr AUXR = 0x8E; //Auxiliary Register T0x12 T1x12 UART_M0x6 BRTR S2SMOD BRTx12 EXTRAM S1BRS 0000,0000 //-----------------------------------

sfr AUXR1 = 0xA2; //Auxiliary Register 1 - PCA_P4 SPI_P4 S2_P4 GF2 ADRJ - DPS 0000,0000 /*

PCA_P4:

0, 缺省PCA 在P1 口

1,PCA/PWM 从P1 口切换到P4 口: ECI 从P1.2 切换到P4.1 口, PCA0/PWM0 从P1.3 切换到P4.2 口

PCA1/PWM1 从P1.4 切换到P4.3 口 SPI_P4:

0, 缺省SPI 在P1 口

1,SPI 从P1 口切换到P4 口: SPICLK 从P1.7 切换到P4.3 口 MISO 从P1.6 切换到P4.2 口 MOSI 从P1.5 切换到P4.1 口 SS 从P1.4 切换到P4.0 口 S2_P4:

0, 缺省UART2 在P1 口

1,UART2 从P1 口切换到P4 口: TxD2 从P1.3 切换到P4.3 口 RxD2 从P1.2 切换到P4.2 口 GF2: 通用标志位

ADRJ:

0, 10 位A/D 转换结果的高8 位放在ADC_RES 寄存器, 低2 位放在ADC_RESL 寄存器

1,10 位A/D 转换结果的最高2 位放在ADC_RES 寄存器的低2 位, 低8 位放在ADC_RESL 寄存器

DPS: 0, 使用缺省数据指针DPTR0 1,使用另一个数据指针DPTR1 */

//-----------------------------------

sfr WAKE_CLKO = 0x8F; //附加的 SFR WAK1_CLKO /*

7 6 5 4 3 2 1 0 Reset Value

PCAWAKEUP RXD_PIN_IE T1_PIN_IE T0_PIN_IE LVD_WAKE _ T1CLKO T0CLKO 0000,0000B

b7 - PCAWAKEUP : PCA 中断可唤醒 powerdown。

b6 - RXD_PIN_IE : 当 P3.0(RXD) 下降沿置位 RI 时可唤醒 powerdown(必须打开相应中断)。

b5 - T1_PIN_IE : 当 T1 脚下降沿置位 T1 中断标志时可唤醒 powerdown(必须打开相应中断)。

b4 - T0_PIN_IE : 当 T0 脚下降沿置位 T0 中断标志时可唤醒 powerdown(必须打开相应中断)。

b3 - LVD_WAKE : 当 CMPIN 脚低电平置位 LVD 中断标志时可唤醒 powerdown(必须打开相应中断)。 b2 -

b1 - T1CLKO : 允许 T1CKO(P3.5) 脚输出 T1 溢出脉冲,Fck1 = 1/2 T1 溢出率 b0 - T0CLKO : 允许 T0CKO(P3.4) 脚输出 T0 溢出脉冲,Fck0 = 1/2 T1 溢出率 */

//-----------------------------------

本文来源:https://www.bwwdw.com/article/m2oh.html

Top