⑴ 51单片机C语言这个是什么意思啊
定义一个了一uchar类型的变量 temp1,和一个uchar类型的数组,数组包含10个元素。0X开头表示16进制的数字。 例如:0X81 = 129。 从名字来看,uchar应该是 unsigned char的意思,即无符号的char类型(1个byte),表示的数值范围是 0 ~ 255。
⑵ 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单片机 c语言中
#define POWER_UP_MARK 0xAB定义POWER_UP_MARK为0xAB 也就是说POWER_UP_MARK和0XAB等价,可以互换,
给个例子,如
struct student
{
int age;//定义年龄
string name;//定义姓名
};
student stu1;
这时候用stu1.age代表stu1对象的年龄
stu1.name代表stu1对象的姓名
⑷ 51单片机C语言中<<=和|=的意思是什么
这两个都是特殊的赋值运算符。这类运算符的形式为OP=,为双目运算符,即需要左右都有操作表达式。其中左侧必须为可改变值的变量,右侧可以为任意表达式。
对于OP=的运算符,其含义为:
aOP=b; 等同于a = a OP b;
对于题目中涉及的两个运算符,分别为:
a <<= b; 等效于a = a << b; 即a左移b位后赋值给a。
左移操作的规则为,高b位舍去,其它依次向高位(左侧)移动b位,低b位添加0。
a|=b;等效于a=a|b;即a与b执行按位或操作,结果赋值给a。
或操作的规则为,按位执行,只有相同位上的值均为0时,结果的对应位上为0,否则结果对应位上为1。
⑸ 51单片机C语言比较
不太明白你说不用比较的意思
⑹ 51单片机c程序
如果前面程序定义了MONITOR51,则编译后面一句,即在地址0X23开始定义只读数组reserve[3]。相反,如果前面程序没有定义MONITOR51,则后面一句不编译。
⑺ 51单片机c语言
例如:
1、这样单独控制,理论上是先后亮的,但CPU跑的快,看起来是同时亮的
sbit led2=P1^1;
sbit led3=P1^2;
void main()
{
led1 = 0;
led2 = 0;
led3 = 0;
}
2、真正同时亮
void main()
{
P1=0xf8;
}
⑻ 51单片机C语言
你自己算一下不就行了?
⑼ 51单片机c语言sbit的作用是什么
在51单片机中,不能直接使用P0^0=xxx操作,因为P0^0是地址值,即指针,P0指针地址值0x80,P0^0指针地址0x81,P0^0=xxx是修改指针地址,即0x81=xxx,明显是错误的,我们想修改指针指向管脚值,必须使用位定义关键字sbit P00 = P0^0;然后P00=xxx,操作P00管脚值,即操作0x81指针指向的管脚P00的值。
⑽ 51单片机S系列与C系列有什么区别
两者主要的区别是AT89S51支持ISP(In System Programming,即“在线可编程”)。而AT89C51无此功能。
以下描述更加详细:
很多初学51单片机的网友会有这样的问题:AT89S51是什么?书上和网络教程上可都是8051,89C51等!没听说过有89S51?!
这里,初学者要澄清单片机实际使用方面的一个产品概念,MCS-51单片机是美国INTE公司于1980年推出的产品,典型产品有 8031(内部没有程序存储器,实际使用方面已经被市场淘汰)、8051(芯片采用HMOS,功耗是630mW,是89C51的5倍,实际使用方面已经被市场淘汰)和8751等通用产品,一直到现在, MCS-51内核系列兼容的单片机仍是应用的主流产品(比如目前流行的89S51、89C51等),各高校及专业学校的培训教材仍与MCS-51单片机作为代表进行理论基础学习。
有些文献甚至也将8051泛指MCS-51系列单片机,8051是早期的最典型的代表作,由于MCS-51单片机影响极深远,许多公司都推出了兼容系列单片机,就是说MCS-51内核实际上已经成为一个8位单片机的标准。
其他的公司的51单片机产品都是和MCS-51内核兼容的产品而以。同样的一段程序,在各个单片机厂家的硬件上运行的结果都是一样的,如ATMEL的89C51(已经停产)、89S51, PHILIPS(菲利浦),和WINBOND(华邦)等,我们常说的已经停产的89C51指的是ATMEL公司的 AT89C51单片机,同时是在原基础上增强了许多特性,如时钟,更优秀的是由Flash(程序存储器的内容至少可以改写1000次)存储器取带了原来的ROM(一次性写入),AT89C51的性能相对于8051已经算是非常优越的了。
不过在市场化方面,89C51受到了PIC单片机阵营的挑战,89C51最致命的缺陷在于不支持ISP(在线更新程序)功能,必须加上ISP功能等新功能才能更好延续MCS-51的传奇。89S51就是在这样的背景下取代89C51的,现在,89S51目前已经成为了实际应用市场上新的宠儿,作为市场占有率第一的Atmel目前公司已经停产AT89C51,将用AT89S51代替。89S51在工艺上进行了改进,89S51采用0.35新工艺,成本降低,而且将功能提升,增加了竞争力。89SXX可以像下兼容89CXX等51系列芯片。同时,Atmel不再接受89CXX的定单,大家在市场上见到的89C51实际都是Atmel前期生产的巨量库存而以。如果市场需要,Atmel当然也可以再恢复生产AT89C51。
89S51相对于89C51增加的新功能包括:
-- 新增加很多功能,性能有了较大提升,价格基本不变,甚至比89C51更低!
-- ISP在线编程功能,这个功能的优势在于改写单片机存储器内的程序不需要把芯片从工作环境中剥离。是一个强大易用的功能。
-- 最高工作频率为33MHz,大家都知道89C51的极限工作频率是24M,就是说S51具有更高工作频率,从而具有了更快的计算速度。
-- 具有双工UART串行通道。
-- 内部集成看门狗计时器,不再需要像89C51那样外接看门狗计时器单元电路。
-- 双数据指示器。
-- 电源关闭标识。
-- 全新的加密算法,这使得对于89S51的**变为不可能,程序的保密性大大加强,这样就可以有效的保护知识产权不被侵犯。
-- 兼容性方面:向下完全兼容51全部字系列产品。比如8051、89C51等等早期MCS-51兼容产品。也就是说所有教科书、网络教程上的程序(不论教科书上采用的单片机是8051还是89C51还是MCS-51等等),在89S51上一样可以照常运行,这就是所谓的向下兼容。
比较结果:就如同INTEL的P3向P4升级一样,虽然都可以跑Windows98,不过速度是不同的。从AT89C51升级到AT89S51 ,也是同理。和S51比起来,C51就要逊色一些,实际应用市场方面技术的进步是永远向前的。
********上面这些就是AT89S51的由来********
下面是初学网友对51系列的选型的常见问题
1问:网友常见问题:请问现在学习51系列单片机应该选择AT89C51还是89S51?
答:89C51和89S51内核相同,89S51针对89C51的明显的几个升级如下 ;
1.程序存储器写入方式:二者的写入程序的方式不同,89C51只支持并行写入,同时需要VPP烧写高压。89S51则支持ISP在线可编程写入技术!串行写入、速度更快、稳定性更好,烧写电压也仅仅需要4~5V即可。
2.电源范围:89S5*电源范围宽达4~5.5V,而89C5*系列在低于4.8V和高于5.3V的时候则无法正常工作。
3.工作频率:目前89S1*的性能远高于89C5*,89S5*系列支持最高高达33MHZ的工作频率,而89C51工作频率范围最高只支持到24M。
4.市场价格:由于89C51已经全面停产,所以在市场价格方面,库存的89C5*的批发价格要比89S5*贵将近一倍!
5.兼容型:89S5*向下兼容89C5*,就是说用89S5*可以替代89C5*使用,同样的程序,运行结果相同。就是说89S5*也同样兼容目前所有的教科书范例程序。
6.加密功能:89S5*系列全新的加密算法,这使得对于89S51的**变为不可能,程序的保密性大大加强,这样就可以有效的保护知识产权不被侵犯。
7.抗干扰性:内部集成看门狗计时器,不再需要像89C51那样外接看门狗计时器单元电路。
8.烧写寿命更长:89S5*标称的1000次,实际最少是1000次~10000次,这样更有利初学者反复烧写,减低学习成本。综合上面的一些区别,个人认为89C51的停止使用只是时间问题而已,就象当年的8031。
2问:采用89C2051开发制造产品是不是要比用89S51更好?因为2051看起来体积比较小。
答:这个问题并不能一概而论,主要的区别如下:
1.功能差别:因为2051不是标准的51内核,所以205*的程序不能直接移植到51上。由于205*是精简型,所以P口变得很少,这样一来就只能用来做一些小的简单产品,可利用资源比较紧张。实际上,做产品的话用205*是不一定合算的,除非是非常简单的产品。
2.市场价格:由于89C2051的产量不是非常大,所以市场价格方面89C2051的批发价格和89S51比较接近!相对性能价格比就比较低。
3.产品体积:除非对产品的体积有苛刻的要求,否则二者的PCB面积相差不多,因为40脚的51芯片也有PLCC44小体积封装。