怎么能实现2进制的输出
时间:10-02
整理:3721RD
点击:
下面是我的程序段。求大神帮帮我怎么输出2进制的显示
#include <c8051f350.h> // SFR declarations
//-----------------------------------------------------------------------------
// Global CONSTANTS
//-----------------------------------------------------------------------------
sbit LED20 = P2^0; // LED='1' means ON. //=0, 熄灭! //=1, 点亮!
sbit Pin01 = P0^1; // 端口P0.1
//-----------------------------------------------------------------------------
// Function PROTOTYPES
//-----------------------------------------------------------------------------
void SYSCLK_Init();
void PORT_Init();
void Timer_Init();
void UART_Init();
void delayms(int time);
//******************************************************************************************
//3:OK(Ver:2.1)
// a I/O口: P1.7 P1.6 P1.5 P1.4 P1.3 P1.2 P1.1 P1.0
// --- 数码管各段: DP g f e d c b a
// f| g |b 1: 0 0 0 0 0 1 1 0 0x06;
// --- 2: 0 1 0 1 1 0 1 1 0x5B;
// e| |c 3: 0 1 0 0 1 1 1 1 0x4F;
// --- .h 4: 0 1 1 0 0 1 1 0 0x66;
// d 5: 0 1 1 0 1 1 0 1 0x6D;
// 6: 0 1 1 1 1 1 0 1 0x7D;
// 7: 0 0 0 0 0 1 1 1 0x07;
// 8: 0 1 1 1 1 1 1 1 0x7F;
// 9: 0 1 1 0 1 1 1 1 0x6F;
// 0: 0 0 1 1 1 1 1 1 0x3F;
//*******************************************************************************************/
unsigned code TAB[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; //OK
//数码管为共阴极 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
//-----------------------------------------------------------------------------
// MAIN Routine
//
// 目的:熟悉P0.0位LED显示静止数字及程序分支结构。
// 串口发来字符"0-9",程序回应数值0-9, LED末位显示数值0-9
// 串口发来字符"A",程序回应数值1显示白色笑脸. 减半P2.0引脚电平的闪烁频率。
// 串口发来字符"B",程序回应数值2显示黑色笑脸. 倍增P2.0引脚电平的闪烁频率。
// 串口发来字符"Esc",程序退出.
// 串口发来其余字符,程序将字符直接回传.
//
//-----------------------------------------------------------------------------
void main() {
long lWaitSetting, lWaitCounter1; // Misc. counters
unsigned char Command0;
unsigned char cNo, cP0;
// disable watchdog timer
PCA0MD &= ~0x40; // WDTE = 0 (clear watchdog timer)
// WDTE = 1 (enable)
SYSCLK_Init (); // Initialize system clock
PORT_Init (); // Initialize crossbar and GPIO
Timer_Init();
UART_Init();
delayms(200);
lWaitSetting = 8750; //175000 --> 1Hz
cP0 = 0;
P0 = 0;
P1 = 0;
RI0 = 0;
TEST:
while (RI0 == 0) {
lWaitCounter1++;
if (lWaitCounter1 > lWaitSetting) {
lWaitCounter1 = 0;
};
if (lWaitCounter1 < lWaitSetting / 2) {
LED20 = 0; //=0, 熄灭!
}
else {
LED20 = 1; //=1, 点亮!
};
};
Command0 = SBUF0;
RI0 = 0; //RI 接收中断标志位由软件清零.
switch (Command0) {
case 1: //F51系统复位
SBUF0 = 11;
break;
case 0x2E: //测试: "."
SBUF0 = Command0; //超级终端回显.
P1 = 0x80; //P1显示字段
break;
case 0x30:
while (RI0 == 0) {
P1=TAB[0] ;
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0] ;
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0] ;
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0]; }
case 0x31:
P1=TAB[0] ;
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0] ;
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1] ;
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0] ;
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0] ;
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
case 0x32:
P1=TAB[0];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1] ;
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0] ;
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
case 0x33:
P1=TAB[0];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0] ;
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1] ;
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1] ;
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
case 0x34:
while (RI0 == 0) {
P1=TAB[0];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0] ;
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
case 0x35:
while (RI0 == 0) {
P1=TAB[0];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
case 0x36:
P1=TAB[0] ;
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1] ;
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
case 0x37:
P1=TAB[0];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
case 0x38:
P1=TAB[1];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
case 0x39:
P1=TAB[1];
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
SBUF0 = Command0; //超级终端回显.
cNo = Command0 - 0x30;
P1 = TAB[cNo]; //P1显示数字
if (cP0 == 0) P0 = 1; //cP0位LED显示静止数字
break;
}
P1 = 0xFF; //P1显示字段
delayms(500);
}
P0MDOUT = 0xF0;
if (Pin01 == 0) {
lWaitSetting = 17500; //175000 --> 1Hz =0, 正常频率闪烁!
}
else {
lWaitSetting = 4375; //4分之一频率闪烁!
};
P0MDOUT = 0xFF; //全部引脚设为推挽方式.
P0 = 0; //P0.0位LED显示静止数字
P1 = 0; //P1显示字段
break;
default: //超级终端回显.
//SBUF0 = Command0;
SBUF0 = 3;
break;
};
//按键Key2控制P2.0LED闪烁频率
cNo = P0;
//cTemp = P1;
/*
//P0MDOUT = 0x30; //P0.4, 0.5引脚设为推挽方式.
P0MDIN = 0xFF;
P0MDOUT = 0xF0;
P0SKIP = 0xCF; //只保留串口,其余全部被交叉跳过.
XBR1 = 0x40; //交叉开关使能.
P0 = 0xFF;
*/
//if (Pin01 == 0) {
if ((cNo & 2 )== 0) {
lWaitSetting = 17500; //175000 --> 1Hz =0, 正常频率闪烁!
}
else {
//P0 = 0x80;
lWaitSetting = 2000; //4分之一频率闪烁!
};
//P0MDOUT = 0xFF; //全部引脚设为推挽方式.
//PORT_Init (); // Initialize crossbar and GPIO
//P0 = cNo;
//P1 = cTemp;
if (Command0 == 27) RSTSRC = RSTSRC | 0x10; //向SWRSF位(RSTSRC.4)写1强制产生一次系统复位..
goto TEST;
} //End of main()
//-----------------------------------------------------------------------------
// SYSCLK_Init
// This routine initializes the system clock to use the internal 24.5MHz
// oscillator as its clock source. Also enables missing clock detector reset.
//-----------------------------------------------------------------------------
void SYSCLK_Init () {
OSCICN = 0x83; // configure internal oscillator 24.5MHz // its lowest frequency
RSTSRC = 0x04; // enable missing clock detector
}
//-----------------------------------------------------------------------------
// PORT_Init
//-----------------------------------------------------------------------------
void PORT_Init (void) { //使用LED显示的配置.
//P0MDOUT = 0xFF; //全部引脚设为推挽方式.
P0MDOUT = 0x30; //P0.4, 0.5引脚设为推挽方式.
P0SKIP = 0xCF; //只保留串口,其余全部被交叉跳过.
//P1MDOUT = 0x3F; //0x3F空出高位两个DAC引脚,全部引脚设为推挽方式.
P1MDOUT = 0xFF; //全部引脚设为推挽方式.
//P1SKIP = 0x3F;
P2MDOUT = 0x01;
XBR0 = 0x01; //UART TX0,RX0连到端口引脚P0.4 和P0.5
XBR1 = 0x40; //交叉开关使能.
}
void Timer_Init() {
TMOD = 0x21; //01:定时器0作为16位时钟
//20:定时器1作为波特率发生器,8位自动重装
}
void UART_Init() {
SCON0 = 0x10; //SCON0: 8-bit variable bit rate
TCON = 0x40;
//CKCON = 0x01; //无->9600 0x01->19200
TH1 = 0x96; //0x96->9600 0x61->19200
TI0 = 1;
//19200BPS
//CKCON = 0x08;
//TH1 = 0xB1;
}
/////////////////////////////////////////////////////////////////////
//
// Function: delayms(int)
//
// 说明:24MHz内部时钟条件下,延时毫秒倍数.
//
/////////////////////////////////////////////////////////////////////
void delayms(int time) {
unsigned char i, j;
while (time>1) {
for(i=0; i<218; i++) for(j=0; j<20; j++);
time--;
}
}
#include <c8051f350.h> // SFR declarations
//-----------------------------------------------------------------------------
// Global CONSTANTS
//-----------------------------------------------------------------------------
sbit LED20 = P2^0; // LED='1' means ON. //=0, 熄灭! //=1, 点亮!
sbit Pin01 = P0^1; // 端口P0.1
//-----------------------------------------------------------------------------
// Function PROTOTYPES
//-----------------------------------------------------------------------------
void SYSCLK_Init();
void PORT_Init();
void Timer_Init();
void UART_Init();
void delayms(int time);
//******************************************************************************************
//3:OK(Ver:2.1)
// a I/O口: P1.7 P1.6 P1.5 P1.4 P1.3 P1.2 P1.1 P1.0
// --- 数码管各段: DP g f e d c b a
// f| g |b 1: 0 0 0 0 0 1 1 0 0x06;
// --- 2: 0 1 0 1 1 0 1 1 0x5B;
// e| |c 3: 0 1 0 0 1 1 1 1 0x4F;
// --- .h 4: 0 1 1 0 0 1 1 0 0x66;
// d 5: 0 1 1 0 1 1 0 1 0x6D;
// 6: 0 1 1 1 1 1 0 1 0x7D;
// 7: 0 0 0 0 0 1 1 1 0x07;
// 8: 0 1 1 1 1 1 1 1 0x7F;
// 9: 0 1 1 0 1 1 1 1 0x6F;
// 0: 0 0 1 1 1 1 1 1 0x3F;
//*******************************************************************************************/
unsigned code TAB[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; //OK
//数码管为共阴极 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
//-----------------------------------------------------------------------------
// MAIN Routine
//
// 目的:熟悉P0.0位LED显示静止数字及程序分支结构。
// 串口发来字符"0-9",程序回应数值0-9, LED末位显示数值0-9
// 串口发来字符"A",程序回应数值1显示白色笑脸. 减半P2.0引脚电平的闪烁频率。
// 串口发来字符"B",程序回应数值2显示黑色笑脸. 倍增P2.0引脚电平的闪烁频率。
// 串口发来字符"Esc",程序退出.
// 串口发来其余字符,程序将字符直接回传.
//
//-----------------------------------------------------------------------------
void main() {
long lWaitSetting, lWaitCounter1; // Misc. counters
unsigned char Command0;
unsigned char cNo, cP0;
// disable watchdog timer
PCA0MD &= ~0x40; // WDTE = 0 (clear watchdog timer)
// WDTE = 1 (enable)
SYSCLK_Init (); // Initialize system clock
PORT_Init (); // Initialize crossbar and GPIO
Timer_Init();
UART_Init();
delayms(200);
lWaitSetting = 8750; //175000 --> 1Hz
cP0 = 0;
P0 = 0;
P1 = 0;
RI0 = 0;
TEST:
while (RI0 == 0) {
lWaitCounter1++;
if (lWaitCounter1 > lWaitSetting) {
lWaitCounter1 = 0;
};
if (lWaitCounter1 < lWaitSetting / 2) {
LED20 = 0; //=0, 熄灭!
}
else {
LED20 = 1; //=1, 点亮!
};
};
Command0 = SBUF0;
RI0 = 0; //RI 接收中断标志位由软件清零.
switch (Command0) {
case 1: //F51系统复位
SBUF0 = 11;
break;
case 0x2E: //测试: "."
SBUF0 = Command0; //超级终端回显.
P1 = 0x80; //P1显示字段
break;
case 0x30:
while (RI0 == 0) {
P1=TAB[0] ;
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0] ;
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0] ;
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0]; }
case 0x31:
P1=TAB[0] ;
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0] ;
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1] ;
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0] ;
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0] ;
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
case 0x32:
P1=TAB[0];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1] ;
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0] ;
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
case 0x33:
P1=TAB[0];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0] ;
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1] ;
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1] ;
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
case 0x34:
while (RI0 == 0) {
P1=TAB[0];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0] ;
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
case 0x35:
while (RI0 == 0) {
P1=TAB[0];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
case 0x36:
P1=TAB[0] ;
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1] ;
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
case 0x37:
P1=TAB[0];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
case 0x38:
P1=TAB[1];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 =cP0 + 1;
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
case 0x39:
P1=TAB[1];
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
if (cP0 > 5) cP0 = 0;//字符升位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[0];
cP0 --;
if (cP0 > 5) cP0 = 5;//字符降位循环
P0 = 1 << cP0; //cP0位LED显示静止数字
if (cP0 == 4) P0 = 1 << 6;
if (cP0 == 5) P0 = 1 << 7;
break;
P1=TAB[1];
SBUF0 = Command0; //超级终端回显.
cNo = Command0 - 0x30;
P1 = TAB[cNo]; //P1显示数字
if (cP0 == 0) P0 = 1; //cP0位LED显示静止数字
break;
}
P1 = 0xFF; //P1显示字段
delayms(500);
}
P0MDOUT = 0xF0;
if (Pin01 == 0) {
lWaitSetting = 17500; //175000 --> 1Hz =0, 正常频率闪烁!
}
else {
lWaitSetting = 4375; //4分之一频率闪烁!
};
P0MDOUT = 0xFF; //全部引脚设为推挽方式.
P0 = 0; //P0.0位LED显示静止数字
P1 = 0; //P1显示字段
break;
default: //超级终端回显.
//SBUF0 = Command0;
SBUF0 = 3;
break;
};
//按键Key2控制P2.0LED闪烁频率
cNo = P0;
//cTemp = P1;
/*
//P0MDOUT = 0x30; //P0.4, 0.5引脚设为推挽方式.
P0MDIN = 0xFF;
P0MDOUT = 0xF0;
P0SKIP = 0xCF; //只保留串口,其余全部被交叉跳过.
XBR1 = 0x40; //交叉开关使能.
P0 = 0xFF;
*/
//if (Pin01 == 0) {
if ((cNo & 2 )== 0) {
lWaitSetting = 17500; //175000 --> 1Hz =0, 正常频率闪烁!
}
else {
//P0 = 0x80;
lWaitSetting = 2000; //4分之一频率闪烁!
};
//P0MDOUT = 0xFF; //全部引脚设为推挽方式.
//PORT_Init (); // Initialize crossbar and GPIO
//P0 = cNo;
//P1 = cTemp;
if (Command0 == 27) RSTSRC = RSTSRC | 0x10; //向SWRSF位(RSTSRC.4)写1强制产生一次系统复位..
goto TEST;
} //End of main()
//-----------------------------------------------------------------------------
// SYSCLK_Init
// This routine initializes the system clock to use the internal 24.5MHz
// oscillator as its clock source. Also enables missing clock detector reset.
//-----------------------------------------------------------------------------
void SYSCLK_Init () {
OSCICN = 0x83; // configure internal oscillator 24.5MHz // its lowest frequency
RSTSRC = 0x04; // enable missing clock detector
}
//-----------------------------------------------------------------------------
// PORT_Init
//-----------------------------------------------------------------------------
void PORT_Init (void) { //使用LED显示的配置.
//P0MDOUT = 0xFF; //全部引脚设为推挽方式.
P0MDOUT = 0x30; //P0.4, 0.5引脚设为推挽方式.
P0SKIP = 0xCF; //只保留串口,其余全部被交叉跳过.
//P1MDOUT = 0x3F; //0x3F空出高位两个DAC引脚,全部引脚设为推挽方式.
P1MDOUT = 0xFF; //全部引脚设为推挽方式.
//P1SKIP = 0x3F;
P2MDOUT = 0x01;
XBR0 = 0x01; //UART TX0,RX0连到端口引脚P0.4 和P0.5
XBR1 = 0x40; //交叉开关使能.
}
void Timer_Init() {
TMOD = 0x21; //01:定时器0作为16位时钟
//20:定时器1作为波特率发生器,8位自动重装
}
void UART_Init() {
SCON0 = 0x10; //SCON0: 8-bit variable bit rate
TCON = 0x40;
//CKCON = 0x01; //无->9600 0x01->19200
TH1 = 0x96; //0x96->9600 0x61->19200
TI0 = 1;
//19200BPS
//CKCON = 0x08;
//TH1 = 0xB1;
}
/////////////////////////////////////////////////////////////////////
//
// Function: delayms(int)
//
// 说明:24MHz内部时钟条件下,延时毫秒倍数.
//
/////////////////////////////////////////////////////////////////////
void delayms(int time) {
unsigned char i, j;
while (time>1) {
for(i=0; i<218; i++) for(j=0; j<20; j++);
time--;
}
}
01显示就行了先把整数换成2进制就行了
我这个是P1进行显示啊?把整数改成啥样啊
转换成16进制,如显示255,直接送FF到P1