导航:首页 > 编程语言 > 51单片机编程

51单片机编程

发布时间:2022-02-09 03:55:14

❶ 51单片机如何在线编程

用串口线连接单片机,然后用keil软件设置下就可以在线编程,但是在你改程序的时候,单片机是不运行的

❷ 51单片机编程

若要将P1.0口设置为高电平,如何编写程序

前面定义 sbit P10 = P1 ^ 0;

后面 P10 = 1;


若要检测P1口上8个引脚是否全为高电平用什么语句

先配置P1口8个引脚为输入状态: P1 = 0xFF;

然后判定条件示例 if (P1 == 0xFF)

❸ 51单片机编程

周期2MS的方波,占空比1:2,不就是1MS高电平1MS低电平?

❹ 51单片机C语言编程

你的设计有点问题,不过你看下这个程序对你应该有帮助。
#include <reg52.h>

#define int8 unsigned char
#define int16 unsigned int
#define int32 unsigned long

int8 flag;
int8 n;
int8 code table[][32]={
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/* " " */

{0x04,0x28,0x08,0x24,0x32,0x22,0xC2,0x21,0xC2,0x26,0x34,0x38,0x04,0x04,0x08,0x18,0x30,0xF0,0xC0,0x17,0x60,0x10,0x18,0x10,0x0C,0x14,0x06,0x18,0x04,0x10,0x00,0x00},/*"欢",0*/
{0x02,0x02,0x04,0x82,0xF8,0x73,0x04,0x20,0x02,0x00,0xE2,0x3F,0x42,0x20,0x82,0x40,0x02,0x40,0xFA,0x3F,0x02,0x20,0x42,0x20,0x22,0x20,0xC2,0x3F,0x02,0x00,0x00,0x00},/*"迎",1*/
{0x00,0x01,0x04,0x02,0x1C,0x0C,0xC0,0x3F,0x1C,0xC0,0x02,0x09,0x02,0x16,0x92,0x60,0x4A,0x20,0x82,0x2F,0x02,0x20,0x0E,0x24,0x00,0x22,0x90,0x31,0x0C,0x20,0x00,0x00},/*"您",2*/
{0x44,0x10,0x44,0x14,0x88,0x54,0x88,0x54,0xD0,0x5F,0x30,0x50,0x60,0x50,0xFE,0x7F,0x40,0x50,0x20,0x90,0xB0,0x9F,0x98,0x92,0x8C,0x94,0x88,0x34,0x80,0x11,0x00,0x00},/*"乘",3*/
{0x82,0x00,0x02,0x01,0x22,0x06,0x22,0x38,0x22,0x04,0x22,0x03,0x22,0x00,0xFE,0xFF,0xA2,0x00,0x22,0x01,0x22,0x02,0x22,0x3C,0x22,0x02,0x02,0x01,0x02,0x00,0x00,0x00},/*"坐",4*/
{0x02,0x00,0x0C,0x00,0xF0,0x3F,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0xA0,0x00,0x60,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x00},/*"广",5*/
{0x80,0x00,0x01,0x07,0x06,0x00,0x18,0x00,0xE0,0xFF,0x00,0x04,0x00,0x03,0x00,0x00,0xFE,0x7F,0x00,0x08,0x00,0x06,0x80,0x01,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00},/*"州",6*/
{0x00,0x00,0x04,0x20,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x20,0x04,0x00,0x00,0x00},/*"三",7*/
{0x20,0x08,0x20,0x86,0x7F,0x60,0x80,0x0F,0x00,0x04,0x00,0x1A,0x00,0xEA,0x00,0x2A,0x00,0x2A,0x00,0x2A,0x00,0x2A,0xF0,0x2B,0x0C,0x28,0x02,0x20,0x0F,0x00,0x00,0x00},/*"汽",8*/
{0x00,0x00,0x80,0x00,0x04,0x01,0x0E,0x02,0x14,0x0C,0x24,0x70,0xC4,0x21,0x8C,0x00,0x08,0x00,0x08,0x70,0x28,0x08,0x1E,0x06,0x0C,0x03,0x80,0x01,0x00,0x01,0x00,0x00},/*"公",9*/
{0x00,0x00,0x00,0x08,0xF8,0x49,0x20,0x49,0x20,0x49,0x20,0x49,0x20,0x49,0x20,0x49,0x20,0x49,0xF0,0x49,0x00,0x48,0x04,0x40,0x02,0x40,0xFC,0x7F,0x00,0x00,0x00,0x00},/*"司",10*/
{0x00,0x00,0x80,0x00,0x04,0x01,0x0E,0x02,0x14,0x0C,0x24,0x70,0xC4,0x21,0x8C,0x00,0x08,0x00,0x08,0x70,0x28,0x08,0x1E,0x06,0x0C,0x03,0x80,0x01,0x00,0x01,0x00,0x00},/*"公",11*/
{0x40,0x00,0x40,0x08,0x41,0x08,0x42,0x08,0x4C,0x08,0xF8,0x7F,0x50,0x08,0x40,0x08,0x40,0x08,0x60,0x08,0xD0,0x7F,0x4C,0x08,0x47,0x08,0x42,0x08,0x40,0x00,0x00,0x00},/*"共",12*/
{0x20,0x08,0x20,0x86,0x7F,0x60,0x80,0x0F,0x00,0x04,0x00,0x1A,0x00,0xEA,0x00,0x2A,0x00,0x2A,0x00,0x2A,0x00,0x2A,0xF0,0x2B,0x0C,0x28,0x02,0x20,0x0F,0x00,0x00,0x00},/*"汽",13*/
{0x20,0x00,0x20,0x20,0x20,0x21,0x20,0x23,0x20,0x25,0x20,0x39,0x20,0xE1,0x20,0x21,0xFF,0x2F,0x20,0x21,0x20,0x21,0x20,0x21,0x20,0x21,0x20,0x21,0x20,0x00,0x00,0x00},/*"车",14*/
{0x00,0x00,0x00,0x00,0x1A,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*",",15*/
{0x00,0x04,0x01,0x04,0x02,0x04,0x04,0x04,0x08,0x04,0x30,0x04,0xC0,0x05,0x00,0xFE,0x80,0x05,0x60,0x04,0x10,0x04,0x0C,0x04,0x06,0x04,0x03,0x04,0x02,0x04,0x00,0x00},/*"大",16*/
{0x00,0x02,0x40,0x0C,0x40,0x08,0x40,0x48,0x40,0x3A,0x40,0x2A,0x42,0x0A,0x41,0x8A,0xFE,0x7A,0x40,0x2B,0x40,0x0A,0x40,0x18,0x40,0xEA,0x40,0x4C,0x40,0x08,0x00,0x00},/*"学",17*/
{0x20,0x08,0x30,0x08,0xE0,0xFF,0x42,0x08,0x4C,0x08,0xF0,0x1F,0x10,0x12,0x1A,0x12,0xF2,0x13,0x04,0x10,0xC8,0xFF,0x30,0x10,0xCC,0x50,0x02,0x37,0x1C,0x12,0x00,0x00},/*"城",18*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x0E,0x14,0x10,0x24,0x10,0x44,0x10,0x84,0x11,0x0C,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"2",0*/
{0x04,0x02,0x44,0x06,0xC4,0x1A,0x48,0xE3,0x48,0x46,0x48,0x00,0x04,0x09,0x04,0x09,0x08,0x09,0xC8,0xFF,0x30,0x09,0x28,0x49,0x44,0x39,0x02,0x29,0x1F,0x01,0x00,0x00},/*"线",19*/
{0x00,0x02,0x02,0x42,0x04,0x42,0x08,0x42,0x30,0x42,0xC0,0x7F,0x00,0x42,0x00,0x42,0x00,0x42,0x00,0x42,0xFE,0x7F,0x00,0x42,0x00,0x42,0x00,0x42,0x00,0x42,0x00,0x00},/*"开",20*/
{0x40,0x04,0x80,0x08,0x00,0x11,0xFF,0xEF,0x00,0x44,0x02,0x10,0x82,0x10,0x82,0x10,0x82,0x90,0xFE,0x7F,0x82,0x50,0x82,0x10,0x82,0x10,0x82,0x10,0x02,0x10,0x00,0x00},/*"往",21*/
{0x00,0x04,0x01,0x04,0x02,0x04,0x04,0x04,0x08,0x04,0x30,0x04,0xC0,0x05,0x00,0xFE,0x80,0x05,0x60,0x04,0x10,0x04,0x0C,0x04,0x06,0x04,0x03,0x04,0x02,0x04,0x00,0x00},/*"大",22*/
{0x00,0x02,0x40,0x0C,0x40,0x08,0x40,0x48,0x40,0x3A,0x40,0x2A,0x42,0x0A,0x41,0x8A,0xFE,0x7A,0x40,0x2B,0x40,0x0A,0x40,0x18,0x40,0xEA,0x40,0x4C,0x40,0x08,0x00,0x00},/*"学",23*/
{0x20,0x08,0x30,0x08,0xE0,0xFF,0x42,0x08,0x4C,0x08,0xF0,0x1F,0x10,0x12,0x1A,0x12,0xF2,0x13,0x04,0x10,0xC8,0xFF,0x30,0x10,0xCC,0x50,0x02,0x37,0x1C,0x12,0x00,0x00},/*"城",24*/
{0x00,0x00,0x00,0x00,0x1A,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*",",25*/
{0x00,0x02,0x00,0x42,0x00,0x32,0xFE,0x23,0x04,0x00,0x08,0x44,0xFF,0x55,0x50,0x55,0x50,0x55,0x50,0xFD,0x52,0x55,0x51,0x55,0xFE,0x55,0x00,0x44,0x00,0x04,0x00,0x00},/*"请",26*/
{0x00,0x01,0x04,0x02,0x1C,0x0C,0xC0,0x3F,0x1C,0xC0,0x02,0x09,0x02,0x16,0x92,0x60,0x4A,0x20,0x82,0x2F,0x02,0x20,0x0E,0x24,0x00,0x22,0x90,0x31,0x0C,0x20,0x00,0x00},/*"您",27*/
{0x82,0x00,0x02,0x01,0x22,0x06,0x22,0x38,0x22,0x04,0x22,0x03,0x22,0x00,0xFE,0xFF,0xA2,0x00,0x22,0x01,0x22,0x02,0x22,0x3C,0x22,0x02,0x02,0x01,0x02,0x00,0x00,0x00},/*"坐",28*/
{0x01,0x08,0xC2,0x08,0x44,0x0F,0x28,0xF8,0x30,0x08,0xCE,0x0F,0x04,0x01,0x00,0x41,0x02,0x41,0x01,0x41,0xFE,0x4F,0x00,0x51,0x00,0x61,0x00,0x41,0x00,0x01,0x00,0x00},/*"好",29*/
{0x42,0x08,0x81,0x08,0xFE,0xFF,0x00,0x09,0x01,0x0A,0x01,0x01,0x02,0x11,0x0C,0x11,0x30,0x11,0xC0,0xFF,0x30,0x11,0x08,0x11,0x06,0x11,0x03,0x11,0x02,0x01,0x00,0x00},/*"扶",30*/
{0x20,0x08,0xC0,0x48,0x00,0x4B,0xFF,0x7F,0x00,0x89,0x9C,0x88,0x00,0x10,0xBC,0x2A,0x82,0xCA,0xC2,0x4A,0xB2,0x5A,0x82,0x6A,0xAE,0x0A,0x90,0x0F,0x0C,0x00,0x00,0x00},/*"稳",31*/
{0x00,0x00,0x00,0x00,0x00,0x00,0xFA,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"!",32*/

{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}/* " " */
};

void delay(void);
int16 offset;

void main(void)
{
int8 i;
int8 *p;
flag=0x10;
n=0;
TMOD=0x01;
TH0=0xb1;
TL0=0xe0;
ET0=1;
EA=1;
TR0=1;

p=&table[0][0];

while (1)
{
for (i=0;i<8;i++) //显示左半边屏幕
{
P0=*(p+offset+2*i);
P2=i|0x08; //P2.4=0,P2.3=1 选中U2, 输出扫描码给U6
delay();

P0=*(p+offset+2*i+1);
P2=i|0x10; //P2.4=1,P2.3=0 选中U3, 输出扫描码给U7
delay();
}
for (i=8;i<16;i++) //显示右半边屏幕
{
P0=*(p+offset+2*i);
P2=(i-8)|0x20; //P2.5=1 P2.4=0, P2.3=0 选中U4,输出扫描码U8
delay();

P0=*(p+offset+2*i+1);
P2=(i-8)|0x40; //P2.6=1 P2.5=0, P2.4=0 选中U5,输出扫描码U9
delay();
}
}
}

void delay(void)
{
int16 i;
for (i=0;i<50;i++)
;
}

void timer0() interrupt 1 using 3
{
TF0=0;
TH0=0xb1;
TL0=0xe0;
if (n<10)
{
n++;
}
else
{
offset+=2;
if (offset>1100)
offset=0;
n=0;
}
}

❺ 关于51单片机的程序

MOV B, #100
DIV AB
MOV 21H, A
MOV A, #10
XCH A, B
DIV AB
SWAP A
ADD A, B
MOV 22H, A

SJMP $

❻ 用51单片机编程

单片机中只有一条语句是对进制调整的
DA A 对累加器A的结果进行十进制调整
如果随意对一个累加器A中的二进制数据进行“二进制转十进制”调整是没有任何实际意义的!

DA调整的对象是ADD或ADDC以后的结果,而且是BCD码相加以后才能够加以调整,否则没有实际意义!

比如,现在我想执行12D+39D也就是两个十进制数相加这样一个加法(有时候程序处理的需要,数据在单片机中是以BCD码的形式存储的,也就是12H和39H(十六进制),但我们可以人为将它们看为12D和39D(十进制),而且还希望相加以后的结果为51H,也就是说符合十进制运算规则12+39=51,而不是4BH的结果),但这样的十进制加法运算在单片机中是不能够直接实现的。因为单片机只能够执行二进制加法指令,也就是所有的运算都按照二进制中的规则进行!

于是就出现了DA调整指令!

现在12H+39H,将12H放于A中,执行 ADD A,#39H指令,则结果为4BH,这不是我们希望的51H的数据形式!!这时执行DA A 指令后,就会将A中的数据调整为51H(具体调整过程和原理你可以详细看书,如果单片机书中讲的不详细,那么微机原理中一定说的非常详细),而我们按照BCD码规则就将其看为51D,符合我们的要求!

也就是说加数和被加数都是BCD码的形式,最大也只可能是99H,也就是我们十进制数中的99,只有这样才会有实际的意义!
所以DA A指令只用于十进制BCD码加法指令以后,否则是没有实际意义的!
在单片机中数据就是以二进制存放的也可以说是以16进制存放(4位二进制就是16进制),所以一般来说在单片机只有二进制转十进制才有意义,通过单片机将十进制转二进制是没意义的。 这个一般都是我们自己把一个十进制数转成二进制再送给单片机处理。
非得编写程序的话 程序如下
----------------------------------------------------------------------
;二进制整数(2位)转换为十进制整数(组合BCD码)
;入口: R3,R4
;出口: R0
IBTD22 : MOV A,R0
PUSH A
MOV R7,#03H
CLR A
IBD221 : MOV @R0,A
INC R0
DJNZ R7,IBD221
POP A
MOV R0,A
MOV R7,#10H
IBD222 : PUSH A
CLR C
MOV A,R4
RLC A
MOV R4,A
MOV A,R3
RLC A
MOV R3,A
MOV B,#03H
IBD223 : MOV A,@R0
ADDC A,@R0
DA A
MOV @R0,A
INC R0
DJNZ B,IBD223
POP A
MOV R0,A
DJNZ
--------------------------------------------------
;二进制整数(M位)转换为十进制整数(组合BCD码)
;入口: R1,M,N
;出口: R0
IBTDMN : MOV A,R0
MOV R2,A
MOV A,R1
MOV R3,A
MOV B,N
CLR A
IBDMN1 : MOV @R0,A
INC R0
DJNZ B,IBDMN1
MOV A,M
SWAP A
RR A
CLR C
MOV R7,A
IBDMN2 : MOV A,R2
MOV R0,A
MOV A,R3
MOV R1,A
MOV B,M
IBDMN3 : MOV A,@R1
RLC A
MOV @R1,A
INC R1
DJNZ B,IBDMN3
MOV B,N
IBDMN4 : MOV A,@R0
ADDC A,@R0
DA A
JNB ACC.4,IBDMN5
SETB C
CLR ACC.4
IBDMN5 : MOV @R0,A
INC R0
DJNZ B,IBDMN4
DJNZ R7,IBDMN2
MOV A,R2
MOV R0,A
RET
----------------------------------------------------------------
BCD整数转换为二进制整数(1位)
;入口: R0(高位地址),R7
;出口: R4
IDTB1: CLR A
MOV R4,A
IDB11: MOV A,R4
MOV B,#0AH
MUL AB
ADD A,@R0
INC R0
MOV R4,A
DJNZ R7,IDB11
RET
------------------------------------------
;BCD整数转换为二进制整数(N位)
;入口: R1(高位地址),M,N
;出口: R0
IDTBMN : MOV A,R0
MOV R2,A
MOV B,N
CLR A
IDBMN1 : MOV @R0,A
INC R0
DJNZ B,IDBMN1
MOV A,R2
MOV R0,A
MOV A,M
MOV NCNT,A
IDBMN2 : MOV R7,N
CLR A
CLR F0
IDBMN3 : XCH A,@R0
MOV B,#0AH
MUL AB
MOV C,F0
ADDC A,@R0
MOV F0,C
MOV @R0,A
INC R0
MOV A,B
DJNZ R7,IDBMN3
MOV A,R2
MOV R0,A
MOV A,@R1
INC R1
ADD A,@R0
MOV @R0,A
DJNZ NCNT,IDBMN2
RET
----------------------------------------------------------
NDIV31 : MOV A,R2
MOV B,R7
DIV AB
PUSH A
MOV R2,B
MOV B,#10H
NDV311 : CLR C
MOV A,R4
RLC A
MOV R4,A
MOV A,R3
RLC A
MOV R3,A
MOV A,R2
RLC A
MOV R2,A
MOV F0,C
CLR C
SUBB A,R7
JB F0,NDV312
JC NDV313
NDV312 : MOV R2,A
INC R4
NDV313 : DJNZ B,NDV311
POP A
CLR OV
JZ NDV314
SETB OV
NDV314 : XCH A,R2
MOV R7,A
RET

❼ 51单片机用什么软件编程

开源软件mcu8051ide 功能不是一般的强,用c语言编程,界面不输给商业软件,而且提供多种模拟器件如:led 数码管,矩阵数码管(8×8)按键,矩阵按键,甚至温度传感器。开源的没有任何限制,完全免费,自动生成多种烧录文件(我们一般就用.HEX的)感觉keil c弱爆了。
安装方法,下载sdcc(mcu8051ide是基于sdcc的)和mcu 8051 ide都安装好就可以啦,头文件在sdcc的安装文件夹内(include)有些关键字要加两个连在一起的下划线比如 __interrup, __code.
头文件与keil的不通用,比如定义P0口
在keil下是: sfr P0=0x80; 在sdcc下是: __sfr __at P0 0x80; 这个P0^1的不行,但sdcc里面有很多头文件8051.h 80c51.h 80c52.h等等 基本满足要求,给stc单片机编程不用改,加一点特殊的就可以。这样优秀的开源软件不用真的是白不用啊。

❽ 关于51单片机程序

MOV DPTR, #ASC_TAB
MOV A, HEX
MOVC A, @A+DPTR
MOV HEX, A

SJMP $

ASC_TAB:
DB 30H, 31H, 32H, 33H, 34H, 35H, 36H, 37H, 38H, 39H
DB 41H, 42H, 43H, 44H, 45H, 46H

❾ 51单片机c语言编程

对端口输出操作,直接适用赋值语句即可。 比如 P1 = 0x03;
对端口读取操作,直接赋值给局部变量即可。
对数码管操作,需要先定义 对应的 码表, Tab[16] = {, }分别对应 0~F 的端口输出值、点亮相应的LED位; 然后直接 操作端口输出对应字符即可,比如P1=Tab[3] 数码管输出显示3

❿ MC51单片机编程

现在我还没法编,没有相应的软件,等明天后天我给你编一个

阅读全文

与51单片机编程相关的资料

热点内容
linux限制用户命令 浏览:740
8p咋设置应用加密 浏览:284
我说你这个我听是什么安卓 浏览:23
云计算算程序员吗 浏览:786
vim编译php 浏览:527
如何正确使用国家反诈中心app 浏览:181
编译执行方式的过程 浏览:489
当量计算法的适用条件 浏览:445
arm单片机开发环境 浏览:401
小米怎么调文件夹大小 浏览:339
程序员怒吼视频 浏览:810
加密货币的发展情况如何 浏览:71
java泛型编译原理 浏览:962
足球23关算法 浏览:736
我的世界手机基岩版为什么进不了服务器 浏览:732
阿里云服务器会被经常攻击吗 浏览:485
百度云app解压了在哪里 浏览:627
金立s10查看加密空间 浏览:865
自动分配ip地址是由什么服务器完成的 浏览:64
和多号app从哪里下载 浏览:348