附件为:LCD12864显示汉字和数字的程序与电路 /* 自定义延时子函数 */ void delayms(uchar z) { int x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } /* 判断LCD忙信号状态 */ void buys() { int dat; RW=1; RS=0; do { P0=0x00; E=1; dat=P0; E=0; dat=0x80 & dat; } while(!(dat==0x00)); } /* LCD写指令函数 */ void w_com(uchar com) { //buys(); RW=0; RS=0; E=1; P0=com; E=0; } /* LCD写数据函数 */ void w_date(uchar date) { //buys(); RW=0; RS=1; E=1; P0=date; E=0; } /* LCD选屏函数 */ void select_screen(uchar screen) { switch(screen) { case 0: //选择全屏 CS1=0; CS2=0; break; case 1: //选择左屏 CS1=0; CS2=1; break; case 2: //选择右屏 CS1=1; CS2=0; break; /* case 3: //选择右屏 CS1=1; CS2=1; break; */ } } /* LCDx向上滚屏显示 */ void lcd_rol() { int x; for(x=0;x<64;x++) { select_screen(0); w_com(0xc0+x); delayms(500); } } /* LCD清屏函数:清屏从第一页的第一列开始,总共8页,64列 */ void clear_screen(screen) { int x,y; select_screen(screen); //screen:0-选择全屏,1-选择左半屏,2-选择右半屏 for(x=0xb8;x<0xc0;x++) //从0xb8-0xbf,共8页 { w_com(x); w_com(0x40); //列的初始地址是0x40 for(y=0;y<64;y++) { w_date(0x00); } } } /* LCD显示汉字字库函数 */ void lcd_display_hanzi(uchar screen,uchar page,uchar col,uint mun) { //screen:选择屏幕参数,page:选择页参数0-3,col:选择列参数0-3,mun:显示第几个汉字的参数 int a; mun=mun*32; select_screen(screen); w_com(0xb8+(page*2)); w_com(0x40+(col*16)); for ( a=0;a<16;a++) { w_date(hanzi[mun++]); } w_com(0xb8+(page*2)+1); w_com(0x40+(col*16)); for ( a=0;a<16;a++) { w_date(hanzi[mun++]); } } /* LCD显示字符字库函数 */ void lcd_display_zifuk(uchar screen,uchar page,uchar col,uchar mun) { //screen:选择屏幕参数,page:选择页参数0-3,col:选择列参数0-7,mun:显示第几个汉字的参数 int a; mun=mun*16; select_screen(screen); w_com(0xb8+(page*2)); w_com(0x40+(col*8)); for ( a=0;a<8;a++) { w_date(zifu[mun++]); } w_com(0xb8+(page*2)+1); w_com(0x40+(col*8)); for ( a=0;a<8;a++) { w_date(zifu[mun++]); } } /* LCD显示数字字库函数 */ void lcd_display_shuzi(uchar screen,uchar page,uchar col,uchar mun) { //screen:选择屏幕参数,page:选择页参数0-3,col:选择列参数0-7,mun:显示第几个汉字的参数 int a; mun=mun*16; select_screen(screen); w_com(0xb8+(page*2)); w_com(0x40+(col*8)); for ( a=0;a<8;a++) { w_date(shuzi[mun++]); } w_com(0xb8+(page*2)+1); w_com(0x40+(col*8)); for ( a=0;a<8;a++) { w_date(shuzi[mun++]); } } /* LCD初始化函数 */ void lcd_init() { w_com(0x3f); //LCD开显示 w_com(0xc0); //LCD行初始地址,共64行 w_com(0xb8); //LCD页初始地址,共8页 w_com(0x40); //LCD列初始地址,共64列 } /* LCD显示主函数 */ void main() { //第一行 int x; lcd_init(); //LCD初始化 clear_screen(0); //LCD清屏幕 lcd_display_shuzi(1,0,4,5); //LCD显示数字 lcd_display_shuzi(1,0,5,1); //LCD显示数字 lcd_display_hanzi(1,0,3,0); //LCD显示汉字 lcd_display_hanzi(2,0,0,1); //LCD显示汉字 //LCD字符汉字 lcd_display_hanzi(2,0,1,2); //LCD显示汉字 //第二行 lcd_display_zifuk(1,1,2,0); //LCD显示字符 lcd_display_zifuk(1,1,3,0); //LCD显示字符 lcd_display_zifuk(1,1,4,0); //LCD显示字符 lcd_display_zifuk(1,1,5,4); //LCD显示字符 lcd_display_shuzi(1,1,6,8); //LCD显示字符 lcd_display_shuzi(1,1,7,9); //LCD显示字符 lcd_display_shuzi(2,1,0,5); //LCD显示字符 lcd_display_shuzi(2,1,1,1); //LCD显示字符 lcd_display_zifuk(2,1,2,4); lcd_display_zifuk(2,1,3,1); lcd_display_zifuk(2,1,4,2); lcd_display_zifuk(2,1,5,3); //第三行 for(x=0;x<4;x++) { lcd_display_hanzi(1,2,x,3+x); //LCD显示汉字 } for(x=0;x<4;x++) { lcd_display_hanzi(2,2,x,7+x); //LCD显示汉字 } //第四行 for(x=0;x<4;x++) { lcd_display_zifuk(1,3,x,5+x); //LCD显示汉字 } lcd_display_shuzi(1,3,4,7); lcd_display_shuzi(1,3,5,5); lcd_display_shuzi(1,3,6,5); lcd_display_zifuk(1,3,7,9); lcd_display_shuzi(2,3,0,8); lcd_display_shuzi(2,3,1,9); lcd_display_shuzi(2,3,2,9); lcd_display_shuzi(2,3,3,5); lcd_display_shuzi(2,3,4,6); lcd_display_shuzi(2,3,5,8); lcd_display_shuzi(2,3,6,9); lcd_display_shuzi(2,3,7,2); while(1); /* while(1) { // LCD向上滚屏显示 lcd_rol(); } */ }
上传时间: 2013-11-08
上传用户:aeiouetla
TLC2543是TI公司的12位串行模数转换器,使用开关电容逐次逼近技术完成A/D转换过程。由于是串行输入结构,能够节省51系列单片机I/O资源;且价格适中,分辨率较高,因此在仪器仪表中有较为广泛的应用。 TLC2543的特点 (1)12位分辩率A/D转换器; (2)在工作温度范围内10μs转换时间; (3)11个模拟输入通道; (4)3路内置自测试方式; (5)采样率为66kbps; (6)线性误差±1LSBmax; (7)有转换结束输出EOC; (8)具有单、双极性输出; (9)可编程的MSB或LSB前导; (10)可编程输出数据长度。 TLC2543的引脚排列及说明 TLC2543有两种封装形式:DB、DW或N封装以及FN封装,这两种封装的引脚排列如图1,引脚说明见表1 TLC2543电路图和程序欣赏 #include<reg52.h> #include<intrins.h> #define uchar unsigned char #define uint unsigned int sbit clock=P1^0; sbit d_in=P1^1; sbit d_out=P1^2; sbit _cs=P1^3; uchar a1,b1,c1,d1; float sum,sum1; double sum_final1; double sum_final; uchar duan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; uchar wei[]={0xf7,0xfb,0xfd,0xfe}; void delay(unsigned char b) //50us { unsigned char a; for(;b>0;b--) for(a=22;a>0;a--); } void display(uchar a,uchar b,uchar c,uchar d) { P0=duan[a]|0x80; P2=wei[0]; delay(5); P2=0xff; P0=duan[b]; P2=wei[1]; delay(5); P2=0xff; P0=duan[c]; P2=wei[2]; delay(5); P2=0xff; P0=duan[d]; P2=wei[3]; delay(5); P2=0xff; } uint read(uchar port) { uchar i,al=0,ah=0; unsigned long ad; clock=0; _cs=0; port<<=4; for(i=0;i<4;i++) { d_in=port&0x80; clock=1; clock=0; port<<=1; } d_in=0; for(i=0;i<8;i++) { clock=1; clock=0; } _cs=1; delay(5); _cs=0; for(i=0;i<4;i++) { clock=1; ah<<=1; if(d_out)ah|=0x01; clock=0; } for(i=0;i<8;i++) { clock=1; al<<=1; if(d_out) al|=0x01; clock=0; } _cs=1; ad=(uint)ah; ad<<=8; ad|=al; return(ad); } void main() { uchar j; sum=0;sum1=0; sum_final=0; sum_final1=0; while(1) { for(j=0;j<128;j++) { sum1+=read(1); display(a1,b1,c1,d1); } sum=sum1/128; sum1=0; sum_final1=(sum/4095)*5; sum_final=sum_final1*1000; a1=(int)sum_final/1000; b1=(int)sum_final%1000/100; c1=(int)sum_final%1000%100/10; d1=(int)sum_final%10; display(a1,b1,c1,d1); } }
上传时间: 2013-11-19
上传用户:shen1230
#include<reg51.h> //包含单片机寄存器的头文件 /******************************************************* 函数功能:主函数 (C 语言规定必须有也只能有1 个主函数) ********************************************************/ void main(void) { while(1) //无限循环 { P1=0xff; // P1=1111 1111B,熄灭LED P0=P1; // 将 P1 口状态送入P0 口 P2=P1; // 将 P1 口状态送入P2 口 P3=P1; // 将 P1 口状态送入P3 口
上传时间: 2013-10-26
上传用户:离殇
一、 main.c(35): warning: #128-D: loop is not reachable from preceding code 原因,前面有一个while(1){ …….} 二、 main.c(54): warning: #1-D: last line of file ends without a newline 少了一个回车在}之后
上传时间: 2014-12-26
上传用户:sjb555
单片机c语言学习和单片机制作资料: 函数的使用和熟悉 实例3:用单片机控制第一个灯亮 实例4:用单片机控制一个灯闪烁:认识单片机的工作频率 实例5:将 P1口状态分别送入P0、P2、P3口:认识I/O口的引脚功能 实例6:使用P3口流水点亮8位LED 实例7:通过对P3口地址的操作流水点亮8位LED 实例8:用不同数据类型控制灯闪烁时间 实例9:用P0口、P1 口分别显示加法和减法运算结果 实例10:用P0、P1口显示乘法运算结果 实例11:用P1、P0口显示除法运算结果 实例12:用自增运算控制P0口8位LED流水花样 实例13:用P0口显示逻辑"与"运算结果 实例14:用P0口显示条件运算结果 实例15:用P0口显示按位"异或"运算结果 实例16:用P0显示左移运算结果 实例17:"万能逻辑电路"实验 实例18:用右移运算流水点亮P1口8位LED 实例19:用if语句控制P0口8位LED的流水方向 实例20:用swtich语句的控制P0口8位LED的点亮状态 实例21:用for语句控制蜂鸣器鸣笛次数 实例22:用while语句控制LED 实例23:用do-while语句控制P0口8位LED流水点亮 实例24:用字符型数组控制P0口8位LED流水点亮 实例25: 用P0口显示字符串常量 实例26:用P0 口显示指针运算结果 实例27:用指针数组控制P0口8位LED流水点亮 实例28:用数组的指针控制P0 口8 位LED流水点亮 实例29:用P0 、P1口显示整型函数返回值 实例30:用有参函数控制P0口8位LED流水速度 实例31:用数组作函数参数控制流水花样 实例32:用指针作函数参数控制P0口8位LED流水点亮 实例33:用函数型指针控制P1口灯花样 实例34:用指针数组作为函数的参数显示多个字符串
上传时间: 2013-10-21
上传用户:llandlu
为提高温度测量效率,降低系统的成本,扩展传输距离,设计出一种新型温度采集系统。单片机通过控制具有单总线方式的温度传感器DS18B20实现对温度的测量,同时单片机通过控制具有单总线方式300~450MHz频率范围内的MAX7044与MAX7033无线发射与接收芯片实现温度数据的无线传输。与传统温度采集系统相比,该系统利用单总线方式连接,采用无线传输方式实现远距离通信,易于系统的集成与扩展。实验结果表明,该系统结构简单、方便移植,能够同时实现多达上百点温度的测量与500m范围的传输。 Abstract: To improve the temperature measurement efficiency and reduce system cost,expansion of transmission distance,a new type of temperature acquisition system is designed.Microcontroller controlled temperature sensor DS18B20which has a single-bus achieves temperature measurement,while microcontroller by controlled the MAX7044and MAX7033chip with a single-bus and having300~450MHz radiofrequency to achieve the wireless transmission of temperature data.Compared with conventional temperature acquisition system,the system uses single-bus connected,and uses wireless transmission means to achieve long-distance communications,easy-to-system integration and expansion.The experimental results show that the system is simple,convenient transplantation,and can be implemented in as many as a hundred-point temperature measure-ment and the transmission range of500meters.
上传时间: 2013-10-29
上传用户:515414293
NXP Semiconductor designed the LPC2400 microcontrollers around a 16-bit/32-bitARM7TDMI-S CPU core with real-time debug interfaces that include both JTAG andembedded Trace. The LPC2400 microcontrollers have 512 kB of on-chip high-speedFlash memory. This Flash memory includes a special 128-bit wide memory interface andaccelerator architecture that enables the CPU to execute sequential instructions fromFlash memory at the maximum 72 MHz system clock rate. This feature is available onlyon the LPC2000 ARM Microcontroller family of products. The LPC2400 can execute both32-bit ARM and 16-bit Thumb instructions. Support for the two Instruction Sets meansEngineers can choose to optimize their application for either performance or code size atthe sub-routine level. When the core executes instructions in Thumb state it can reducecode size by more than 30 % with only a small loss in performance while executinginstructions in ARM state maximizes core performance.
上传时间: 2013-11-15
上传用户:zouxinwang
C51 中的关键字关键字 用途 说明auto 存储种类说明 用以说明局部变量,缺省值为此break 程序语句 退出最内层循环case 程序语句 Switch 语句中的选择项char 数据类型说明 单字节整型数或字符型数据const 存储类型说明 在程序执行过程中不可更改的常量值continue 程序语句 转向下一次循环default 程序语句 Switch 语句中的失败选择项do 程序语句 构成do..while 循环结构double 数据类型说明 双精度浮点数else 程序语句 构成if..else 选择结构enum 数据类型说明 枚举extern 存储种类说明 在其他程序模块中说明了的全局变量flost 数据类型说明 单精度浮点数for 程序语句 构成for 循环结构goto 程序语句 构成goto 转移结构if 程序语句 构成if..else 选择结构int 数据类型说明 基本整型数long 数据类型说明 长整型数register 存储种类说明 使用CPU 内部寄存的变量return 程序语句 函数返回short 数据类型说明 短整型数signed 数据类型说明 有符号数,二进制数据的最高位为符号位sizeof 运算符 计算表达式或数据类型的字节数static 存储种类说明 静态变量struct 数据类型说明 结构类型数据swicth 程序语句 构成switch 选择结构typedef 数据类型说明 重新进行数据类型定义union 数据类型说明 联合类型数据unsigned 数据类型说明 无符号数数据void 数据类型说明 无类型数据volatile 数据类型说明 该变量在程序执行中可被隐含地改变while 程序语句 构成while 和do..while 循环结构ANSIC 标准关键字关键字 用途 说明bit 位标量声明 声明一个位标量或位类型的函数sbit 位标量声明 声明一个可位寻址变量
标签: C51
上传时间: 2013-10-08
上传用户:waves_0801
AT89C2051驱动步进电机的电路和源码:AT89C2051驱动步进电机的电路和源码 程序:stepper.c stepper.hex/* * STEPPER.C * sweeping stepper's rotor cw and cww 400 steps * Copyright (c) 1999 by W.Sirichote */#i nclude c:\mc5151io.h /* include i/o header file */ #i nclude c:\mc5151reg.hregister unsigned char j,flag1,temp; register unsigned int cw_n,ccw_n;unsigned char step[8]={0x80,0xc0,0x40,0x60,0x20,0x30,0x10,0x90} #define n 400/* flag1 mask byte 0x01 run cw() 0x02 run ccw() */main(){ flag1=0; serinit(9600); disable(); /* no need timer interrupt */ cw_n = n; /* initial step number for cw */ flag1 |=0x01; /* initial enable cw() */while(1){ { tick_wait(); /* wait for 10ms elapsed */energize(); /* round-robin execution the following tasks every 10ms */ cw(); ccw(); } }}cw(){ if((flag1&0x01)!=0) { cw_n--; /* decrement cw step number */ if (cw_n !=0) j++; /* if not zero increment index j */ else {flag1&=~0x01; /* disable cw() execution */ ccw_n = n; /* reload step number to ccw counter */ flag1 |=0x02; /* enable cww() execution */ } }
上传时间: 2013-11-21
上传用户:boyaboy
The PCA9516 is a BiCMOS integrated circuit intended forapplication in I2C and SMBus systems.while retaining all the operating modes and features of the I2Csystem, it permits extension of the I2C-bus by buffering both the data(SDA) and the clock (SCL) lines, thus enabling five buses of 400 pF.The I2C-bus capacitance limit of 400 pF restricts the number ofdevices and bus length. Using the PCA9516 enables the systemdesigner to divide the bus into five segments off of a hub where anysegment to segment transition sees only one repeater delay.
上传时间: 2013-11-21
上传用户:q123321