cdecimal头文件|写一个函数输入十六进制数输出相应的十进制数

|

1. 用vs2013写的,我把Decimaltor写在了另一个cpp文件,它说找不到标识符,哪出错了

先用#include 引用实现该函数的定义头文件,然后编译就没问题了。

2. 写一个函数,输入十六进制数,输出相应的十进制数

方法一:

#include<stdio.h>

#include<math.h>

#include<string.h>

void xtod(char s[]);//定义转制函数

int main()

{

char str[10];

printf("Please enter Hex number:");//输入一个字符串

scanf("%s",str);

xtod(str);//调用转制函数

return 0;

}

//转制函数

void xtod(char s[])

{

int i,j,n=strlen(s);

double num[10],sum;

//以下是判断输入的数是否是合法的十六进制数,不是就报错并重新输入

for(i=0;i<n;i++)

if(s<i><'0'||

(s<i>>'9'&&s<i><'A')||s<i>>'f'||

(s<i>>'F'&&s<i><'a')||n>10){

printf("Error!Please enter Hex number:");

scanf("%s",s);

}

//以下将输入的字符转换为十进制数字

for(i=0;i<n;i++){

if(s<i>>='0'&&s<i><='9')

num<i>=s<i>-'0';

if(s<i>>='a'&&s<i><='f')

num<i>=(int)s<i>-87;

if(s<i>>='A'&&s<i><='F')

num<i>=(int)s<i>-55;

}

//将数字转为十进制

for(i=0,j=n-1,sum=0.0;i<n;

sum+=num<i>*pow(16,j),i++,j–);

printf("Decimal number:%.0f",sum);

}

方法二、

#include<stdio.h>

void xtod(int x);//定义转制函数

int main()

{

int i;

scanf("%x",&i);//输入一个十六进制数

xtod(i);//调用转制函数

return 0;

}

//转制函数

void xtod(int x)

{

printf("%d",x);

}

(2)cdecimal头文件扩展阅读:

①printf()函数是格式化输出函数,一般用于向标准输出设备按规定格式输出信息。

格式输出,它是c语言中产生格式化输出的函数(在stdio.h中定义)。用于向终端(显示器、控制台等)输出字符。格式控制由要输出的文字和数据格式说明组成。

要输出的文字除了可以使用字母、数字、空格和一些数字符号以外,还可以使用一些转义字符表示特殊的含义。

简单点理解就是,在一段程序中你正确使用该函数,可以在该程序运行的时候输出你所需要的内容。

②printf函数是一个标准库函数,它的函数原型在头文件“stdio.h”中。但作为一个特例,不要求在使用printf函数之前必须包含stdio.h文件。

printf()函数的调用格式为:printf("<格式化字符串>",<参量表>)。

其中格式化字符串用于指定输出格式。格式控制串可由格式字符串和非格式字符串两种组成。

格式字符串是以%开头的字符串,在%后面跟有各种格式字符,以说明输出数据的类型、形式、长度、小数位数等。

如“%d”表示按十进制整型输出,“%ld”表示按十进制长整型输出,“%C”表示按字符型输出等。

非格式字符串在输出时原样照印,在显示中起提示作用。输出表列中给出了各个输出项,要求格式字符串和各输出项在数量和类型上应该一一对应。

3. 关于c语言的头文件问题

如果定义了__STDC__,就说明这个编译器遵循标准C。所以把_Cdecl定义为空字符串,也就是相当于把所有的_Cdecl删除了。如果没有定义__STDC__,就是明这个编译器不遵循标准C。那么把_Cdecl定义为 cdecl。其实cdecl可能也是一个宏,当编译器支持一个叫“调用约定”的扩展时,cdecl被定义成这种扩展的语法。之所以有这段条件编译是因为标准C不支持“调用约定”。

4. 什么情况下要加头文件math.h

math.h The math header defines several mathematic functions. Macros: HUGE_VAL Functions: acos(); asin(); atan(); atan2(); ceil(); cos(); cosh(); exp(); fabs(); floor(); fmod(); frexp(); ldexp(); log(); log10(); modf(); pow(); sin(); sinh(); sqrt(); tan(); tanh(); 2.7.1 Error Conditions All math.h functions handle errors similarly. In the case that the argument passed to the function exceeds the range of that function, then the variable errno is set to EDOM. The value that the function returns is implementation specific. In the case that the value being returned is too large to be represented in a double, then the function returns the macro HUGE_VAL, and sets the variable errno to ERANGE to represent an overflow. If the value is too small to be represented in a double, then the function returns zero. In this case whether or not errno is set to ERANGE is implementation specific. errno, EDOM, and ERANGE are defined in the errno.h header. Note that in all cases when it is stated that there is no range limit, it is implied that the value is limited by the minimum and maximum values of type double. 2.7.2 Trigonometric Functions 2.7.2.1 acos Declaration: double acos(double x); Returns the arc cosine of x in radians. Range: The value x must be within the range of -1 to +1 (inclusive). The returned value is in the range of 0 to pi (inclusive). 2.7.2.2 asin Declaration: double asin(double x); Returns the arc sine of x in radians. Range: The value of x must be within the range of -1 to +1 (inclusive). The returned value is in the range of -p/2 to +p/2 (inclusive). 2.7.2.3 atan Declaration: double atan(double x); Returns the arc tangent of x in radians. Range: The value of x has no range. The returned value is in the range of -p/2 to +p/2 (inclusive). 2.7.2.4 atan2 Declaration: double atan2(doubly y, double x); Returns the arc tangent in radians of y/x based on the signs of both values to determine the correct quadrant. Range: Both y and x cannot be zero. The returned value is in the range of -p/2 to +p/2 (inclusive). 2.7.2.5 cos Declaration: double cos(double x); Returns the cosine of a radian angle x. Range: The value of x has no range. The returned value is in the range of -1 to +1 (inclusive). 2.7.2.6 cosh Declaration: double cosh(double x); Returns the hyperbolic cosine of x. Range: There is no range limit on the argument or return value. 2.7.2.7 sin Declaration: double sin(double x); Returns the sine of a radian angle x. Range: The value of x has no range. The returned value is in the range of -1 to +1 (inclusive). 2.7.2.8 sinh Declaration: double sinh(double x); Returns the hyperbolic sine of x. Range: There is no range limit on the argument or return value. 2.7.2.9 tan Declaration: double tan(double x); Returns the tangent of a radian angle x. Range: There is no range limit on the argument or return value. 2.7.2.10 tanh Declaration: double tanh(double x); Returns the hyperbolic tangent of x. Range: The value of x has no range. The returned value is in the range of -1 to +1 (inclusive). 2.7.3 Exponential, Logarithmic, and Power Functions 2.7.3.1 exp Declaration: double exp(double x); Returns the value of e raised to the xth power. Range: There is no range limit on the argument or return value. 2.7.3.2 frexp Declaration: double frexp(double x, int *exponent); The floating-point number x is broken up into a mantissa and exponent. The returned value is the mantissa and the integer pointed to by exponent is the exponent. The resultant value is x=mantissa * 2^exponent. Range: The mantissa is in the range of .5 (inclusive) to 1 (exclusive). 2.7.3.3 ldexp Declaration: double ldexp(double x, int exponent); Returns x multiplied by 2 raised to the power of exponent. x*2^exponent Range: There is no range limit on the argument or return value. 2.7.3.4 log Declaration: double log(double x); Returns the natural logarithm (base-e logarithm) of x. Range: There is no range limit on the argument or return value. 2.7.3.5 log10 Declaration: double log10(double x); Returns the common logarithm (base-10 logarithm) of x. Range: There is no range limit on the argument or return value. 2.7.3.6 modf Declaration: double modf(double x, double *integer); Breaks the floating-point number x into integer and fraction components. The returned value is the fraction component (part after the decimal), and sets integer to the integer component. Range: There is no range limit on the argument or return value. 2.7.3.7 pow Declaration: double pow(double x, double y); Returns x raised to the power of y. Range: x cannot be negative if y is a fractional value. x cannot be zero if y is less than or equal to zero. 2.7.3.8 sqrt Declaration: double sqrt(double x); Returns the square root of x. Range: The argument cannot be negative. The returned value is always positive. 2.7.4 Other Math Functions 2.7.4.1 ceil Declaration: double ceil(double x); Returns the smallest integer value greater than or equal to x. Range: There is no range limit on the argument or return value. 2.7.4.2 fabs Declaration: double fabs(double x); Returns the absolute value of x (a negative value becomes positive, positive value is unchanged). Range: There is no range limit on the argument. The return value is always positive. 2.7.4.3 floor Declaration: double floor(double x); Returns the largest integer value less than or equal to x. Range: There is no range limit on the argument or return value. 2.7.4.4 fmod Declaration: double fmod(double x, double y); Returns the remainder of x divided by y. Range: There is no range limit on the return value. If y is zero, then either a range error will occur or the function will return zero (implementation-defined).

5. 这个程序什么意思啊,我不明白此程序是什么意思 为什么b=a&3; 输出结果时是3呢 谢谢亲 告诉我吧!

#include "stdio.h" //引入头文件 基本输入输出main(){int a,b; //定义变量a=077; //给a变量赋8进制的77也就是十进制的63的值b=a&3; //给b变量赋值 先将077和3转为二进制 然后在与 规则是: 0&0为0,0&1为0,1&1为1 结果为3printf("\40: The a & b(decimal) is %d \n",b); //打印出bb&=7; //给b变量赋值 先将3和7转为二进制 然后在与 规则是: 0&0为0,0&1为0,1&1为1 结果为3printf("\40: The a & b(decimal) is %d \n",b); //打印出b}

6. 有关gcvt函数的问题

1、gcvt是把浮点数转换成字符串,同时返回一个指向字符串的存储位置的指针的函数。

2、用法: char *gcvt(double value, int ndigit, char *buf);

包含头文件:<stdlib.h>

参数

value——被转换的值。

Digits——存储的有效数字位数。

Buffe——结果的存储位置。

返回值

返回一个指向结果的存储位置的指针

3、说明:gcvt函数把一个浮点值转换成一个字符串(包括一个小数点和可能的符号字节)并存储该字符串在buffer中。该buffer应足够大以便容纳转换的值加上结尾的空字符(''),它是自动添加的。如果一个缓冲区的尺寸为digits的尺寸+1,该函数覆盖该缓冲区的末尾。这是因为转换的字符串包括一个小数点以及可能包含符号和指数信息。不提供上溢出。gcvt试图以十进制格式产生digits数字,如果不可能,它以指数格式产生digits数字,在转换时可能截除尾部的0。

4、示例:

7. c语言头文件哪错了不能引用

#include<reg51.h>这个是系统的吗?如果不是的,你自己写的要用#include"reg51.h"

8. 电子万年历

#include<reg51.h>#include"DS18B20_3.H"#define uint unsigned int#define uchar unsigned charuchar a,miao,shi,fen,ri,yue,nian,week,flag,key1n,temp;//flag用于读取头文件中的温度值,和显示温度值#define yh 0x80 //LCD第一行的初始位置,因为LCD1602字符地址首位D7恒定为1(100000000=80)#define er 0x80+0x40 //LCD第二行初始位置(因为第二行第一个字符位置地址是0x40)//液晶屏的与C51之间的引脚连接定义(显示数据线接C51的P0口)sbit rs=P2^0;sbit en=P2^2;sbit rw=P2^1; //如果硬件上rw接地,就不用写这句和后面的rw=0了sbit led=P2^6; //LCD背光开关//DS1302时钟芯片与C51之间的引脚连接定义sbit IO=P1^1;sbit SCLK=P1^0;sbit RST=P1^2;sbit ACC0=ACC^0;sbit ACC7=ACC^7;/************************************************************ACC累加器=AACC.0=E0H ACC.0就是ACC的第0位。Acc可以位寻址。累加器ACC是一个8位的存储单元,是用来放数据的。但是,这个存储单元有其特殊的地位,是单片机中一个非常关键的单元,很多运算都要通过ACC来进行。以后在学习指令时,常用A来表示累加器。但有一些地方例外,比如在PUSH指令中,就必须用ACC这样的名字。一般的说法,A代表了累加器中的内容、而ACC代表的是累加器的地址。 ***************************************************************///校时按键与C51的引脚连接定义sbit key1=P1^5; //设置键sbit key2=P1^6; //加键sbit key3=P1^7; //减键sbit buzzer=P1^3;//蜂鸣器,通过三极管9012驱动,端口低电平响/**************************************************************/uchar code tab1[]={"20 – – "}; //年显示的固定字符uchar code tab2[]={" : : "};//时间显示的固定字符//延时函数,后面经常调用void delay(uint xms)//延时函数,有参函数{ uint x,y; for(x=xms;x>0;x–) for(y=110;y>0;y–);}/********液晶写入指令函数与写入数据函数,以后可调用**************//*在这个程序中,液晶写入有关函数会在DS1302的函数中调用,所以液晶程序要放在前面*/write_1602com(uchar com)//****液晶写入指令函数****{ rs=0;//数据/指令选择置为指令 rw=0; //读写选择置为写 P0=com;//送入数据 delay(1); en=1;//拉高使能端,为制造有效的下降沿做准备 delay(1); en=0;//en由高变低,产生下降沿,液晶执行命令}write_1602dat(uchar dat)//***液晶写入数据函数****{ rs=1;//数据/指令选择置为数据 rw=0; //读写选择置为写 P0=dat;//送入数据 delay(1); en=1; //en置高电平,为制造下降沿做准备 delay(1); en=0; //en由高变低,产生下降沿,液晶执行命令}lcd_init()//***液晶初始化函数****{ write_1602com(0x38);//设置液晶工作模式,意思:16*2行显示,5*7点阵,8位数据 write_1602com(0x0c);//开显示不显示光标 write_1602com(0x06);//整屏不移动,光标自动右移 write_1602com(0x01);//清显示 write_1602com(yh+1);//日历显示固定符号从第一行第1个位置之后开始显示 for(a=0;a<14;a++) { write_1602dat(tab1[a]);//向液晶屏写日历显示的固定符号部分 //delay(3); } write_1602com(er+2);//时间显示固定符号写入位置,从第2个位置后开始显示 for(a=0;a<8;a++) { write_1602dat(tab2[a]);//写显示时间固定符号,两个冒号 //delay(3); }}/*********************over***********************//***************DS1302有关子函数********************/void write_byte(uchar dat)//写一个字节{ ACC=dat; RST=1; for(a=8;a>0;a–) { IO=ACC0; SCLK=0; SCLK=1; ACC=ACC>>1; }}uchar read_byte()//读一个字节{ RST=1; for(a=8;a>0;a–) { ACC7=IO; SCLK=1; SCLK=0; ACC=ACC>>1; } return (ACC);}//—————————————-void write_1302(uchar add,uchar dat)//向1302芯片写函数,指定写入地址,数据{ RST=0; SCLK=0; RST=1; write_byte(add); write_byte(dat); SCLK=1; RST=0;}uchar read_1302(uchar add)//从1302读数据函数,指定读取数据来源地址{ uchar temp; RST=0; SCLK=0; RST=1; write_byte(add); temp=read_byte(); SCLK=1; RST=0; return(temp);}uchar BCD_Decimal(uchar bcd)//BCD码转十进制函数,输入BCD,返回十进制{ uchar Decimal; Decimal=bcd>>4; return(Decimal=Decimal*10+(bcd&=0x0F));}//————————————–void ds1302_init() //1302芯片初始化子函数(2010-01-07,12:00:00,week4){RST=0;SCLK=0;write_1302(0x8e,0x00); //允许写,禁止写保护 //write_1302(0x80,0x00); //向DS1302内写秒寄存器80H写入初始秒数据00//write_1302(0x82,0x00);//向DS1302内写分寄存器82H写入初始分数据00//write_1302(0x84,0x12);//向DS1302内写小时寄存器84H写入初始小时数据12//write_1302(0x8a,0x04);//向DS1302内写周寄存器8aH写入初始周数据4//write_1302(0x86,0x07);//向DS1302内写日期寄存器86H写入初始日期数据07//write_1302(0x88,0x01);//向DS1302内写月份寄存器88H写入初始月份数据01//write_1302(0x8c,0x10);//向DS1302内写年份寄存器8cH写入初始年份数据10write_1302(0x8e,0x80); //打开写保护}//————————————//温度显示子函数void write_temp(uchar add,uchar dat)//向LCD写温度数据,并指定显示位置{ uchar gw,sw; gw=dat%10;//取得个位数字 sw=dat/10;//取得十位数字 write_1602com(er+add);//er是头文件规定的值0x80+0x40 write_1602dat(0x30+sw);//数字+30得到该数字的LCD1602显示码 write_1602dat(0x30+gw);//数字+30得到该数字的LCD1602显示码 write_1602dat(0xdf);//显示温度的小圆圈符号,0xdf是液晶屏字符库的该符号地址码 write_1602dat(0x43); //显示"C"符号,0x43是液晶屏字符库里大写C的地址码 }//————————————//时分秒显示子函数void write_sfm(uchar add,uchar dat)//向LCD写时分秒,有显示位置加、现示数据,两个参数{ uchar gw,sw; gw=dat%10;//取得个位数字 sw=dat/10;//取得十位数字 write_1602com(er+add);//er是头文件规定的值0x80+0x40 write_1602dat(0x30+sw);//数字+30得到该数字的LCD1602显示码 write_1602dat(0x30+gw);//数字+30得到该数字的LCD1602显示码 }//————————————-//年月日显示子函数void write_nyr(uchar add,uchar dat)//向LCD写年月日,有显示位置加数、显示数据,两个参数{ uchar gw,sw; gw=dat%10;//取得个位数字 sw=dat/10;//取得十位数字 write_1602com(yh+add);//设定显示位置为第一个位置+add write_1602dat(0x30+sw);//数字+30得到该数字的LCD1602显示码 write_1602dat(0x30+gw);//数字+30得到该数字的LCD1602显示码 }//——————————————-void write_week(uchar week)//写星期函数{ write_1602com(yh+0x0c);//星期字符的显示位置 switch(week) { case 1:write_1602dat('M');//星期数为1时,显示 write_1602dat('O'); write_1602dat('N'); break; case 2:write_1602dat('T');//星期数据为2时显示 write_1602dat('U'); write_1602dat('E'); break; case 3:write_1602dat('W');//星期数据为3时显示 write_1602dat('E'); write_1602dat('D'); break; case 4:write_1602dat('T');//星期数据为4是显示 write_1602dat('H'); write_1602dat('U'); break; case 5:write_1602dat('F');//星期数据为5时显示 write_1602dat('R'); write_1602dat('I'); break; case 6:write_1602dat('S');//星期数据为6时显示 write_1602dat('T'); write_1602dat('A'); break; case 7:write_1602dat('S');//星期数据为7时显示 write_1602dat('U'); write_1602dat('N'); break;}}//****************键盘扫描有关函数**********************void keyscan(){ if(key1==0)//—————key1为功能键(设置键)——————– { delay(9);//延时,用于消抖动 if(key1==0)//延时后再次确认按键按下 { buzzer=0;//蜂鸣器短响一次 delay(20); buzzer=1; while(!key1); key1n++; if(key1n==9) key1n=1;//设置按键共有秒、分、时、星期、日、月、年、返回,8个功能循环 switch(key1n) { case 1: TR0=0;//关闭定时器 //TR1=0; write_1602com(er+0x09);//设置按键按动一次,秒位置显示光标 write_1602com(0x0f);//设置光标为闪烁 temp=(miao)/10*16+(miao)%10;//秒数据写入DS1302 write_1302(0x8e,0x00); write_1302(0x80,0x80|temp);//miao write_1302(0x8e,0x80); break; case 2: write_1602com(er+6);//按2次fen位置显示光标 //write_1602com(0x0f); break; case 3: write_1602com(er+3);//按动3次,shi //write_1602com(0x0f); break; case 4: write_1602com(yh+0x0e);//按动4次,week //write_1602com(0x0f); break; case 5: write_1602com(yh+0x0a);//按动5次,ri //write_1602com(0x0f); break; case 6: write_1602com(yh+0x07);//按动6次,yue //write_1602com(0x0f); break; case 7: write_1602com(yh+0x04);//按动7次,nian //write_1602com(0x0f); break; case 8: write_1602com(0x0c);//按动到第8次,设置光标不闪烁 TR0=1;//打开定时器 temp=(miao)/10*16+(miao)%10; write_1302(0x8e,0x00); write_1302(0x80,0x00|temp);//miao数据写入DS1302 write_1302(0x8e,0x80); break; }} }//——————————加键key2—————————- if(key1n!=0)//当key1按下以下。再按以下键才有效(按键次数不等于零) { if(key2==0) //上调键 { delay(10); if(key2==0) { buzzer=0;//蜂鸣器短响一次 delay(20); buzzer=1; while(!key2); switch(key1n) { case 1:miao++;//设置键按动1次,调秒 if(miao==60) miao=0;//秒超过59,再加1,就归零 write_sfm(0x08,miao);//令LCD在正确位置显示"加"设定好的秒数 temp=(miao)/10*16+(miao)%10;//十进制转换成DS1302要求的DCB码 write_1302(0x8e,0x00); //允许写,禁止写保护 write_1302(0x80,temp); //向DS1302内写秒寄存器80H写入调整后的秒数据BCD码 write_1302(0x8e,0x80); //打开写保护 write_1602com(er+0x09);//因为设置液晶的模式是写入数据后,光标自动右移,所以要指定返回 //write_1602com(0x0b); break; case 2:fen++; if(fen==60) fen=0; write_sfm(0x05,fen);//令LCD在正确位置显示"加"设定好的分数据 temp=(fen)/10*16+(fen)%10;//十进制转换成DS1302要求的DCB码 write_1302(0x8e,0x00);//允许写,禁止写保护 write_1302(0x82,temp);//向DS1302内写分寄存器82H写入调整后的分数据BCD码 write_1302(0x8e,0x80);//打开写保护 write_1602com(er+6);//因为设置液晶的模式是写入数据后,指针自动加一,在这里是写回原来的位置 break; case 3:shi++; if(shi==24) shi=0; write_sfm(2,shi);//令LCD在正确的位置显示"加"设定好的小时数据 temp=(shi)/10*16+(shi)%10;//十进制转换成DS1302要求的DCB码 write_1302(0x8e,0x00);//允许写,禁止写保护 write_1302(0x84,temp);//向DS1302内写小时寄存器84H写入调整后的小时数据BCD码 write_1302(0x8e,0x80);//打开写保护 write_1602com(er+3);//因为设置液晶的模式是写入数据后,指针自动加一,所以需要光标回位 break; case 4:week++; if(week==8) week=1; write_1602com(yh+0x0C);//指定'加'后的周数据显示位置 write_week(week);//指定周数据显示内容 temp=(week)/10*16+(week)%10;//十进制转换成DS1302要求的DCB码 write_1302(0x8e,0x00);//允许写,禁止写保护 write_1302(0x8a,temp);//向DS1302内写周寄存器8aH写入调整后的周数据BCD码 write_1302(0x8e,0x80);//打开写保护 write_1602com(yh+0x0e);//因为设置液晶的模式是写入数据后,指针自动加一,所以需要光标回位 break; case 5:ri++; if(ri==32) ri=1; write_nyr(9,ri);//令LCD在正确的位置显示"加"设定好的日期数据 temp=(ri)/10*16+(ri)%10;//十进制转换成DS1302要求的DCB码 write_1302(0x8e,0x00);//允许写,禁止写保护 write_1302(0x86,temp);//向DS1302内写日期寄存器86H写入调整后的日期数据BCD码 write_1302(0x8e,0x80);//打开写保护 write_1602com(yh+10);//因为设置液晶的模式是写入数据后,指针自动加一,所以需要光标回位 break; case 6:yue++; if(yue==13) yue=1; write_nyr(6,yue);//令LCD在正确的位置显示"加"设定好的月份数据 temp=(yue)/10*16+(yue)%10;//十进制转换成DS1302要求的DCB码 write_1302(0x8e,0x00);//允许写,禁止写保护 write_1302(0x88,temp);//向DS1302内写月份寄存器88H写入调整后的月份数据BCD码 write_1302(0x8e,0x80);//打开写保护 write_1602com(yh+7);//因为设置液晶的模式是写入数据后,指针自动加一,所以需要光标回位 break; case 7:nian++; if(nian==100) nian=0; write_nyr(3,nian);//令LCD在正确的位置显示"加"设定好的年份数据 temp=(nian)/10*16+(nian)%10;//十进制转换成DS1302要求的DCB码 write_1302(0x8e,0x00);//允许写,禁止写保护 write_1302(0x8c,temp);//向DS1302内写年份寄存器8cH写入调整后的年份数据BCD码 write_1302(0x8e,0x80);//打开写保护 write_1602com(yh+4);//因为设置液晶的模式是写入数据后,指针自动加一,所以需要光标回位 break;} } } //——————减键key3,各句功能参照'加键'注释————— if(key3==0) { delay(10);//调延时,消抖动 if(key3==0) { buzzer=0;//蜂鸣器短响一次 delay(20); buzzer=1; while(!key3); switch(key1n) { case 1:miao–; if(miao==-1) miao=59;//秒数据减到-1时自动变成59 write_sfm(0x08,miao);//在LCD的正确位置显示改变后新的秒数 temp=(miao)/10*16+(miao)%10;//十进制转换成DS1302要求的DCB码 write_1302(0x8e,0x00); //允许写,禁止写保护 write_1302(0x80,temp); //向DS1302内写秒寄存器80H写入调整后的秒数据BCD码 write_1302(0x8e,0x80); //打开写保护 write_1602com(er+0x09);//因为设置液晶的模式是写入数据后,指针自动加一,在这里是写回原来的位置 //write_1602com(0x0b); break; case 2:fen–; if(fen==-1) fen=59; write_sfm(5,fen); temp=(fen)/10*16+(fen)%10;//十进制转换成DS1302要求的DCB码 write_1302(0x8e,0x00);//允许写,禁止写保护 write_1302(0x82,temp);//向DS1302内写分寄存器82H写入调整后的分数据BCD码 write_1302(0x8e,0x80);//打开写保护 write_1602com(er+6);//因为设置液晶的模式是写入数据后,指针自动加一,在这里是写回原来的位置 break; case 3:shi–; if(shi==-1) shi=23; write_sfm(2,shi); temp=(shi)/10*16+(shi)%10;//十进制转换成DS1302要求的DCB码 write_1302(0x8e,0x00);//允许写,禁止写保护 write_1302(0x84,temp);//向DS1302内写小时寄存器84H写入调整后的小时数据BCD码 write_1302(0x8e,0x80);//打开写保护 write_1602com(er+3);//因为设置液晶的模式是写入数据后,指针自动加一,所以需要光标回位 break; case 4:week–; if(week==0) week=7; write_1602com(yh+0x0C);//指定'加'后的周数据显示位置 write_week(week);//指定周数据显示内容 temp=(week)/10*16+(week)%10;//十进制转换成DS1302要求的DCB码 write_1302(0x8e,0x00);//允许写,禁止写保护 write_1302(0x8a,temp);//向DS1302内写周寄存器8aH写入调整后的周数据BCD码 write_1302(0x8e,0x80);//打开写保护 write_1602com(yh+0x0e);//因为设置液晶的模式是写入数据后,指针自动加一,所以需要光标回位 break; case 5:ri–; if(ri==0) ri=31; write_nyr(9,ri); temp=(ri)/10*16+(ri)%10;//十进制转换成DS1302要求的DCB码 write_1302(0x8e,0x00);//允许写,禁止写保护 write_1302(0x86,temp);//向DS1302内写日期寄存器86H写入调整后的日期数据BCD码 write_1302(0x8e,0x80);//打开写保护 write_1602com(yh+10);//因为设置液晶的模式是写入数据后,指针自动加一,所以需要光标回位 break; case 6:yue–; if(yue==0) yue=12; write_nyr(6,yue); temp=(yue)/10*16+(yue)%10;//十进制转换成DS1302要求的DCB码 write_1302(0x8e,0x00);//允许写,禁止写保护 write_1302(0x88,temp);//向DS1302内写月份寄存器88H写入调整后的月份数据BCD码 write_1302(0x8e,0x80);//打开写保护 write_1602com(yh+7);//因为设置液晶的模式是写入数据后,指针自动加一,所以需要光标回位 break; case 7:nian–; if(nian==-1) nian=99; write_nyr(3,nian); temp=(nian)/10*16+(nian)%10;//十进制转换成DS1302要求的DCB码 write_1302(0x8e,0x00);//允许写,禁止写保护 write_1302(0x8c,temp);//向DS1302内写年份寄存器8cH写入调整后的年份数据BCD码 write_1302(0x8e,0x80);//打开写保护 write_1602com(yh+4);//因为设置液晶的模式是写入数据后,指针自动加一,所以需要光标回位 break;} } } }}//——————————-void init() //定时器、计数器设置函数{ TMOD=0x11; //指定定时/计数器的工作方式为3 TH0=0; //定时器T0的高四位=0 TL0=0; //定时器T0的低四位=0 EA=1; //系统允许有开放的中断 ET0=1; //允许T0中断 TR0=1; //开启中断,启动定时器}//*******************主函数**************************//***************************************************void main(){ lcd_init(); //调用液晶屏初始化子函数 ds1302_init(); //调用DS1302时钟的初始化子函数 init(); //调用定时计数器的设置子函数 led=0; //打开LCD的背光电源 buzzer=0;//蜂鸣器长响一次 delay(80); buzzer=1; while(1) //无限循环下面的语句: { keyscan(); //调用键盘扫描子函数 }}void timer0() interrupt 1 //取得并显示日历和时间{ //Init_DS18B20();//温度传感器DS18b2初始化子函数,在头文件中 flag=ReadTemperature();//将18b2头文件运行返回的函数结果送到变量FLAG中,用于显示 //读取秒时分周日月年七个数据(DS1302的读寄存器与写寄存器不一样):miao = BCD_Decimal(read_1302(0x81)); fen = BCD_Decimal(read_1302(0x83)); shi = BCD_Decimal(read_1302(0x85)); ri = BCD_Decimal(read_1302(0x87)); yue = BCD_Decimal(read_1302(0x89)); nian=BCD_Decimal(read_1302(0x8d)); week=BCD_Decimal(read_1302(0x8b)); //显示温度、秒、时、分数据: write_temp(12,flag);//显示温度,从第二行第12个字符后开始显示 write_sfm(8,miao);//秒,从第二行第8个字后开始显示(调用时分秒显示子函数) write_sfm(5,fen);//分,从第二行第5个字符后开始显示 write_sfm(2,shi);//小时,从第二行第2个字符后开始显示 //显示日、月、年数据: write_nyr(9,ri);//日期,从第二行第9个字符后开始显示 write_nyr(6,yue);//月份,从第二行第6个字符后开始显示 write_nyr(3,nian);//年,从第二行第3个字符后开始显示 write_week(week);}

9. 学习C语言编程想要实现简单的计算器,编辑出现问题,大神来看看是不是头文件有问题

math.h是标准库中的,改成这样试试 #include<math.h>或者你也可以看看哪个类定义后边少了一个分号

10. 为什么Win-Tc里面的头文件只有函数的定义却没有函数的实现

函数的实现已经被编译成dll文件和lib,提供用户调用!在头文件中只给出函数的声明,目的是为了系统对函数的参数类型进行行检查!


赞 (0)