数据类型和运算符、表达式是是C51语言程序设计的最基础知识,C51语言把数据分成了多种数据类型,并提供了丰富的运算对数据进行处理。本章对C51语言的基本数据类型、常量变量、运算符及表达式等进行详细介绍。1.掌握数据类型的概念,了解C51语言能够处理的数据类型。2.掌握常量的概念,掌握各种类型常量的特点及表示形式。3.掌握变量的概念,了解int、float、char型变量的特点,掌握这三种类型变量的定义、赋值和使用方法。理解C51中变量的存储和编译模式的关系,掌握单片机片内资源的访问方法。4.了解C51语言的基本运算符及其特点,掌握运算符的优先级和结合性的概念。5.了解算术运算表达式、关系表达式及逻辑表达式的特点,熟练进行表达式计算,能熟练进行实际问题的表达式描述。6.熟悉自增、自减运算的特点,掌握赋值运算,了解逗号运算符和逗号表达式。7.掌握数据类型转换的概念,能进行基本的数据类型转换。
标签: C51
上传时间: 2013-12-26
上传用户:dingdingcandy
单片机接口技术(C51版)课件:单片机接口技术(C51版)课件精品课程,该书由张道德根据多年单片机教学、科研经验编著,中国水利水电出版社2007年3月出版。 1.掌握数据类型的概念,了解C51语言能够处理的数据类型。2.掌握常量的概念,掌握各种类型常量的特点及表示形式。3.掌握变量的概念,了解int、float、char型变量的特点,掌握这三种类型变量的定义、赋值和使用方法。理解C51中变量的存储和编译模式的关系,掌握单片机片内资源的访问方法。4.了解C51语言的基本运算符及其特点,掌握运算符的优先级和结合性的概念。5.了解算术运算表达式、关系表达式及逻辑表达式的特点,熟练进行表达式计算,能熟练进行实际问题的表达式描述。6.熟悉自增、自减运算的特点,掌握赋值运算,了解逗号运算符和逗号表达式。7.掌握数据类型转换的概念,能进行基本的数据类型转换。
上传时间: 2013-10-10
上传用户:jcljkh
汇编语言在数据处理中应用(自学)1、数值转换中应用 数据输入/输出时的转换2、串操作中应用 串移动、串搜索、串比较、 串插入、串删除3、代码转换中应用 ASCII码 BCD码 二进数 BCD码 4、算术运算 在这一部分,我们将汇编语言在数据处理中的应用集中起来给大家,其中有些程序在11章中已经介绍过。
上传时间: 2013-10-23
上传用户:qwer0574
//芯片资料请到www.elecfans.com查找 //DS1820 C51 子程序//这里以11.0592M晶体为例,不同的晶体速度可能需要调整延时的时间//sbit DQ =P2^1;//根据实际情况定义端口 typedef unsigned char byte;typedef unsigned int word; //延时void delay(word useconds){ for(;useconds>0;useconds--);} //复位byte ow_reset(void){ byte presence; DQ = 0; //pull DQ line low delay(29); // leave it low for 480us DQ = 1; // allow line to return high delay(3); // wait for presence presence = DQ; // get presence signal delay(25); // wait for end of timeslot return(presence); // presence signal returned} // 0=presence, 1 = no part //从 1-wire 总线上读取一个字节byte read_byte(void){ byte i; byte value = 0; for (i=8;i>0;i--) { value>>=1; DQ = 0; // pull DQ low to start timeslot DQ = 1; // then return high delay(1); //for (i=0; i<3; i++); if(DQ)value|=0x80; delay(6); // wait for rest of timeslot } return(value);} //向 1-WIRE 总线上写一个字节void write_byte(char val){ byte i; for (i=8; i>0; i--) // writes byte, one bit at a time { DQ = 0; // pull DQ low to start timeslot DQ = val&0x01; delay(5); // hold value for remainder of timeslot DQ = 1; val=val/2; } delay(5);} //读取温度char Read_Temperature(void){ union{ byte c[2]; int x; }temp; ow_reset(); write_byte(0xCC); // Skip ROM write_byte(0xBE); // Read Scratch Pad temp.c[1]=read_byte(); temp.c[0]=read_byte(); ow_reset(); write_byte(0xCC); //Skip ROM write_byte(0x44); // Start Conversion return temp.x/2;}
上传时间: 2013-11-03
上传用户:hongmo
#include <at24c01a.h>/*************************************************向24C01A写入一个字节输入:E2ROM地址,字节数据******************************************************/void write24c01a(uchar uadd_1,uchar udata_1){sendbyte=0xa0;start();send(sendbyte);if (!ack())continue;send(uadd_1);if (!ack())continue;send(udata_1)if (!ack())continue;stop();}/**********************************发送开始*****************************************/void start(void){a_scl=1;a_sda=1;a_sda=0;a_scl=0;a_scl=1;}/********************************************发送停止*******************************************/void stop(void){a_scl=0;a_sda=0;a_scl=1;a_sda=1;} /*********************************************发送反馈************************************************/bit ack(void){int a_acka_scl=0;a_scl=0;a_scl=0;a_scl=1;a_ack=a_sda;a_scl=0;return(a_ack)}/**************************************发送无反馈********************************************/bit noack(void){int a_ack;a_scl=1;a_scl=1;a_scl=0;}/*******************************************发送****************************************************/void send(uchar undata){uchar i;sendbyte=undatafor(i=8;i>0;i--){a_sda=sendbyte7;a_scl=0;a_scl=1;sendbyte=sendbyte<<1}}/********************************************接受****************************************************/ void receive(void){int i;uchar data;for(i=8;i>0;i--){ a_scl=1;receivebyte7=a_sda;a_scl=0;receivebyte=receivebyte>>1}receivedata=receivebyte;}/********************************************向 24c01a读一个字节;输入:EEROM地址;输出:EEROM数据;********************************************/void read24c01a(uchar counter){receivebyte=0xa1;start();send(receivebyte);if (!ack())continue;send(counter);if (!ack())continue;receive()noack();stop();}
上传时间: 2013-12-23
上传用户:wxhwjf
24c16读写驱动程序,//=-------------------------------------------------------------------------------/*模块调用:读数据:read(unsigned int address)写数据:write(unsigned int address,unsigned char dd) dd为要写的 数据字节*///------------------------------------------------------------------------------ sbit sda=P3^0;sbit scl=P3^1; sbit a0=ACC^0; //定义ACC的位,利用ACC操作速度最快sbit a1=ACC^1;sbit a2=ACC^2;sbit a3=ACC^3;sbit a4=ACC^4;sbit a5=ACC^5;sbit a6=ACC^6;sbit a7=ACC^7; //------------------------------------------------------------------------------#pragma disablevoid s24(void) //起始函数{_nop_(); scl=0; sda=1; scl=1; _nop_(); sda=0; _nop_(); _nop_(); scl=0; _nop_(); _nop_(); sda=1;} //------------------------------------------------------------------------------#pragma disablevoid p24(void) //停止函数{sda=0; scl=1; _nop_(); _nop_(); sda=1;} //-----------------------------------------------------------------------------#pragma disableunsigned char rd24(void) /////////////////从24c16读一字节数据{ ACC=0x00;sda=1;scl=1;a7=sda;_nop_();_nop_();_nop_();_nop_();scl=0;scl=1;a6=sda;_nop_();_nop_();_nop_();_nop_();scl=0;scl=1;a5=sda;_nop_();_nop_();_nop_();_nop_();scl=0;scl=1;a4=sda;_nop_();_nop_();_nop_();_nop_();scl=0;scl=1;a3=sda;_nop_();_nop_();_nop_();_nop_();scl=0;scl=1;a2=sda;_nop_();_nop_();_nop_();_nop_();scl=0;scl=1;a1=sda;_nop_();_nop_();_nop_();_nop_();scl=0;scl=1;a0=sda;_nop_();_nop_();_nop_();_nop_();scl=0;sda=1;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0; /// ///////////////24c16的一位回答位。return(ACC);}//------------------------------------------------------------------------------#pragma disablevoid wd24(unsigned char dd) ////////////////向24c16写一字节数据{ sda=1;ACC=dd;sda=a7;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;sda=a6;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;sda=a5;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;sda=a4;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;sda=a3;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;sda=a2;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;sda=a1;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;sda=a0;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;sda=0;scl=1;//scl=0;(在下面程序中)}//---------------------------------------------------------------------------#pragma disableunsigned char read(unsigned int address){unsigned char dd; s24(); ////////////////////////开始条件 wd24(0xa0); /////////////////////////写器件地址(写命令) _nop_();_nop_();_nop_();_nop_(); scl=0; ///////////////////////////////////接收器件地址确认信号 wd24(address); //////////////////////////// 写数据地址 _nop_();_nop_();_nop_();_nop_(); scl=0;s24(); ///////////////////////////////////开始条件 wd24(0xa1); /////////////////////////////写器件地址(读命令) scl=0; dd=rd24(); //////////////////////////////////读 一字节 p24(); ////////////////////////////////////停止条件 return(dd);}//------------------------------------------------------------------------------#pragma disablevoid write(unsigned int address,unsigned char dd){s24(); /////////////////开始条件 wd24(0xa0); ////////////////////////写器件地址; scl=0; wd24(address); /////////////////////写数据地址 scl=0; wd24(dd); //////////////////////////写dd数据 scl=0; p24(); /////////////////////////停止条件; }
上传时间: 2013-11-18
上传用户:墙角有棵树
C51控制并口打印机实例:/* 沈阳新荣达电子 *//* 2004-12-7 */#include <reg52.h>#define uchar unsigned char#define uint unsigned int#define data_8 P0sbit BUSY = P1^2; //打印机 BUSY 接P1.2sbit STB = P1^0; //打印机 STB 接P1.0void print(uchar j) //打印子程序{ uchar i;while(BUSY){}; //BUSY=1,打印机忙,等待BUSY 为0 再发数data_8=j;STB=0;i++;i--;STB=1; //给出数据锁存时钟BUSY=1;}void main(void){BUSY = 1; //忙信号置高STB = 1; //选通信号置高print(0x1b); //打印机初始化命令print(0x38);print(0x04);for(;;){print(0xd0); //发送汉字内码“新荣达”print(0xc2);print(0xc8);print(0xd9);print(0xb4);print(0xef);print(0x0d); //换行}}
上传时间: 2013-11-13
上传用户:lwq11
微型打印机的C语言源程序:微型打印机的C51源程序#define uchar unsigned char#define uint unsigned int#include <reg52.h>#include <stdio.h>#include <absacc.h>#include <math.h>#include <string.h>#include <ctype.h>#include <stdlib.h>#define PIN XBYTE[0x8000]#define POUT XBYTE[0x9000]sbit PRINTSTB =P1^6;sbit DOG=P1^7;bdata char pin&#118alue;sbit PRINTBUSY=pin&#118alue^7;sbit PRINTSEL =pin&#118alue^6;sbit PRINTERR =pin&#118alue^5;sbit PRINTACK =pin&#118alue^4; void PrintString(uchar *String1,uchar *String2);void initprint(void);void print(uchar a); void initprint(void) //打印机初始化子程序 { pin&#118alue=PIN; if((PRINTSEL==1)&&(PRINTERR==1)) { print(0x1b); print(0x40); print(0x1b); print(0x38); print(0x4); }}void print(uchar a) //打印字符a{ pin&#118alue=PIN; if((PRINTSEL==0)||(PRINTERR==0)) return; for(;;) { DOG=~DOG; pin&#118alue=PIN; if(PRINTBUSY==0) break; } DOG=~DOG; POUT=a; PRINTSTB=1; PRINTSTB=1; PRINTSTB=1; PRINTSTB=1; PRINTSTB=0; PRINTSTB=0; PRINTSTB=0; PRINTSTB=0; PRINTSTB=1;}void PrintString(uchar *String) //打印字符串后回车{ uchar CH; for (;;) { DOG=~DOG; CH=*String; if (CH==0) { print(0x0d); break; } print(CH); String++; } initprint();}
上传时间: 2013-10-18
上传用户:hasan2015
16 16点阵显示汉字原理及显示程序 #include "config.h" #define DOTLED_LINE_PORT PORTB #define DOTLED_LINE_DDR DDRB #define DOTLED_LINE_PIN PINB #define DOTLED_LINE_SCKT PB1 #define DOTLED_LINE_SCKH PB5 #define DOTLED_LINE_SDA PB3 #define DOTLED_ROW_PORT PORTC #define DOTLED_ROW_DDR DDRC #define DOTLED_ROW_PIN PINC #define DOTLED_ROW_A0 PC0 #define DOTLED_ROW_A1 PC1 #define DOTLED_ROW_A2 PC2 #define DOTLED_ROW_A3 PC3 #define DOTLED_ROW_E PC4 uint8 font[] = { /*-- 调入了一幅图像:这是您新建的图像 --*/ /*-- 宽度x高度=16x16 --*/ 0x00,0x00,0x00,0x00,0x08,0x38,0x18,0x44,0x08,0x44,0x08,0x04,0x08,0x08,0x08,0x10, 0x08,0x20,0x08,0x40,0x08,0x40,0x08,0x40,0x3E,0x7C,0x00,0x00,0x00,0x00,0x00,0x00 }; static void TransmitByte(uint8 byte); static void SelectRow(uint8 row); static void FlipLatchLine(void); static void TransmitByte(uint8 byte) { uint8 i; for(i = 0 ; i < 8 ; i ++) { if(byte & (1 << i)) { DOTLED_LINE_PORT |= _BV(DOTLED_LINE_SDA); } else { DOTLED_LINE_PORT &= ~_BV(DOTLED_LINE_SDA); } //__delay_cycles(100); DOTLED_LINE_PORT |= _BV(DOTLED_LINE_SCKH); //__delay_cycles(100); DOTLED_LINE_PORT &= ~_BV(DOTLED_LINE_SCKH); //__delay_cycles(100); } } static void SelectRow(uint8 row) { //row -= 1; row |= DOTLED_ROW_PIN & 0xe0; DOTLED_ROW_PORT = row; } static void FlipLatchLine(void) { DOTLED_LINE_PORT |= _BV(DOTLED_LINE_SCKT); DOTLED_LINE_PORT &= ~_BV(DOTLED_LINE_SCKT); } void InitDotLedPort(void) { DOTLED_LINE_PORT &= ~(_BV(DOTLED_LINE_SCKT) | _BV(DOTLED_LINE_SCKH)); DOTLED_LINE_PORT |= _BV(DOTLED_LINE_SDA); DOTLED_LINE_DDR |= _BV(DOTLED_LINE_SCKT) | _BV(DOTLED_LINE_SCKH) | _BV(DOTLED_LINE_SDA); DOTLED_ROW_PORT |= 0x1f; DOTLED_ROW_PORT &= 0xf0; DOTLED_ROW_DDR |= 0x1f; } void EnableRow(boolean IsEnable) { if(IsEnable) { DOTLED_ROW_PORT &= ~_BV(DOTLED_ROW_E); } else { DOTLED_ROW_PORT |= _BV(DOTLED_ROW_E); } } void PrintDotLed(uint8 * buffer) { uint8 i , tmp; for(i = 0 ; i < 16 ; i ++) { tmp = *buffer ++; TransmitByte(~tmp); tmp = *buffer ++; TransmitByte(~tmp); SelectRow(i); FlipLatchLine(); } } void main(void) { InitDotLedPort(); EnableRow(TRUE); while(1) { PrintDotLed(font); __delay_cycles(5000); } } //---------------------------------------------------- config.h文件 #ifndef _CONFIG_H #define _CONFIG_H //#define GCCAVR #define CPU_CYCLES 7372800L #ifndef GCCAVR #define _BV(bit) (1 << (bit)) #endif #define MSB 0x80 #define LSB 0x01 #define FALSE 0 #define TRUE 1 typedef unsigned char uint8; typedef unsigned int uint16; typedef unsigned long uint32; typedef unsigned char boolean; #include <ioavr.h> #include <inavr.h> #include "dotled.h" #endif //-----
上传时间: 2013-11-18
上传用户:mnacyf
51单片机驱动步进电机(含电路图和源程序代码) 源程序: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.h register 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() */
上传时间: 2013-11-09
上传用户:钓鳌牧马