2 qq 34860335 qq_34860335 于 2016.05.08 12:04 提问

下图问题怎么解决啊?C语言程序

图片说明
#include
#include

#define uchar unsinged char
#define uint unsinged char

#include"LM016LCD_drive.h"
#include"MAX6675_drive.h"
#include"DS1302_drive.h"
#include"PWM.h"

#define beep_0 (PORTD=PORTD&0X7F)
#define beep_1 (PORTD=PORTD|0X81)
#define fosc 11059200
#define baud 9600

uchar count_10ms;
uchar K1_FLAG=1;
uchar tempt;
uchar SEED;
uchar K1=0;
uchar P=0;
//uchar K=0;
uchar line1_data[]={"week"};
//uchar line3_data[]={"Time"};
//uchar line2_data[]={" "};
uchar disp_buf[15]={0x00};
uchar time_buf[7]={0,0,0x12,0,0,0,0,};
uchar temp[2]={0};

//uchar TEMP1[]={0};
/*蜂鸣器响一声函数*/
void beep(uchar L)
{
beep_0;
Delay_ms(L);
beep_1;
Delay_ms(L);
}

/*端口设置函数*/
void port_init(void)
{
PORTA=0xff;
DDRA=0XFF;
DDRB=(1<<PB0)|(1<<PB2)|(1<<PB3)|(1<<PB4)|(1<<PB6)|(1<<PB7);
PORTC=0XFF;
DDRC=0XFF;
DDRD=(0<<PD2)|(0<<PD3)|(0<<PD4)|(0<<PD5)|(0<<PD6)|(1<<PD7);
PORTD=0Xff;
}

/*转换函数,负责将走时数据转换为适合lcd显示的数据*/
void LCD_conv(uchar inl,uchar in2,uchar in3,uchar in4,uchar in5,uchar in6,uchar in7)
{
disp_buf[0]=inl/10+0x30;
disp_buf[1]=inl%10+0x30;
disp_buf[2]=in2/10+0x30;
disp_buf[3]=in2%10+0x30;
disp_buf[4]=in3/10+0x30;
disp_buf[5]=in3%10+0x30;
disp_buf[6]=in4/10+0x30;
disp_buf[7]=in4%10+0x30;
disp_buf[8]=in5/10+0x30;
disp_buf[9]=in5%10+0x30;
disp_buf[10]=in6+0x30;//
disp_buf[11]=2+0x30;
disp_buf[12]=0x30;
disp_buf[13]=in7%100/10+0x30;
disp_buf[14]=in7%10+0x30;
}

/*温度显示函数*/
void temp_disp(void)
{
uint i;
LocateXY(11,1);
for(i=1;i<4;i++)
{
lcd_wdat(show_data[i]);
delay(1);
}
LocateXY(14,1);
lcd_wdat(0xdf);
lcd_wdat(0x43);
}

/*日期时间lcd显示函数*/
void LCD_disp()
{
uchar i;

//LocateXY(10,0);
//lcd_wdat(0x3a);
LocateXY(0,0);
lcd_wdat(disp_buf[11]);
lcd_wdat(disp_buf[12]);
lcd_wdat(disp_buf[13]);
lcd_wdat(disp_buf[14]);
lcd_wdat(0x2f);
lcd_wdat(disp_buf[8]);
lcd_wdat(disp_buf[9]);
lcd_wdat(0x2f);
lcd_wdat(disp_buf[6]);
lcd_wdat(disp_buf[7]);

LocateXY(15,0);
lcd_wdat(disp_buf[10]);

LocateXY(0,1);
lcd_wdat(disp_buf[4]);
lcd_wdat(disp_buf[5]);
lcd_wdat(0x3a);
lcd_wdat(disp_buf[2]);
lcd_wdat(disp_buf[3]);
lcd_wdat(0x3a);
lcd_wdat(disp_buf[0]);
lcd_wdat(disp_buf[1]);

}

/*定时器1初始化*/
/*void timer1_init()
{
SREG=0X80;
//MCUCR=(1<<ISC01)|(1<<ISC00);

TIMSK|=(1<<TOIE1);
TCNT1H=0XFb;
TCNT1L=0X1e;
TCCR1A|=0X00;
TCCR1B|=(1<<CS11)|(1<<CS10);
}
/
/
#pragma interrupt_handler timer0_ovf:10
void timer0_ovf(void)
{

}
/
/
定时器1终端服务函数*/
/*#pragma interrupt_handler timer1_ovf:9
void timer1_ovf(void)
{

}*/

//}
/*if(count_10ms>=100)
{
count_10ms=0;
time_buf[0]++;
if(time_buf[0]==60)
{
time_buf[0]=0;
time_buf[1]++;
if(time_buf[1]==60)
{
time_buf[1]=0;
time_buf[2]++;
if(time_buf[2]==24)
{
time_buf[0]=0;time_buf[1]=0;time_buf[2]=0;
}
}
}
}
}
/
/
按键处理函数*/
void KeyProcess()
{
uint i;
uchar K;
uchar L;
uchar sec16,min16,hour16,day16,mon16,year16,week16;
write_ds1302(0x8e,0x00);
write_ds1302(0x80,0x80);

Delay_ms(10);

if((PIND&0X08)==0)
{
while(!(PIND&0X08));
beep(100);
K=K1_FLAG;
switch(K)
{
/*case 1:
{
time_buf[0]=time_buf[0]+1;
if(time_buf[0]==60)
time_buf[0]=0;
sec16=time_buf[0]/10*16+time_buf[0]%10;
write_ds1302(0x80,sec16);
}*/
//break;
case 1:
{
time_buf[1]=time_buf[1]+1;
if(time_buf[1]==60)
time_buf[1]=0;
min16=time_buf[1]/10*16+time_buf[1]%10;
write_ds1302(0x82,min16);
}
break;
case 2:
{
time_buf[2]=time_buf[2]+1;
if(time_buf[2]==24)
time_buf[2]=0;
hour16=time_buf[2]/10*16+time_buf[2]%10;
write_ds1302(0x84,hour16);
}
break;
case 3:
{
time_buf[5]=time_buf[5]+1;
if(time_buf[5]==8)
time_buf[5]=1;
week16=time_buf[5]/10*16+time_buf[5]%10;
write_ds1302(0x8a,week16);
}
break;
case 4:
{
time_buf[3]=time_buf[3]+1;
if(time_buf[3]==31)
time_buf[3]=1;
day16=time_buf[3]/10*16+time_buf[3]%10;
write_ds1302(0x86,day16);
}
break;
case 5:
{
time_buf[4]=time_buf[4]+1;
if(time_buf[4]==12)
time_buf[4]=0;
mon16=time_buf[4]/10*16+time_buf[4]%10;
write_ds1302(0x88,mon16);
}
break;
case 6:
{
time_buf[6]=time_buf[6]+1;
if(time_buf[6]==99)
time_buf[6]=0;
year16=time_buf[6]/10*16+time_buf[6]%10;
write_ds1302(0x8c,year16);
}
break;
default:break;
}
}

if((PIND&0X10)==0)
{

while(!(PIND&0X10));
beep(100);
L=K1_FLAG;
switch(L)
{

/*case 1:
{
time_buf[0]=time_buf[0]-1;
if(time_buf[0]==0)
time_buf[0]=59;
sec16=time_buf[0]/10*16+time_buf[0]%10;
write_ds1302(0x80,sec16);
}*/
//break;
case 1:
{
time_buf[1]=time_buf[1]-1;
if(time_buf[1]==0)
time_buf[1]=59;
min16=time_buf[1]/10*16+time_buf[1]%10;
//Delay_ms(150);
write_ds1302(0x82,min16);
}
break;

case 2:
{
time_buf[2]=time_buf[2]-1;
if(time_buf[2]==0)
time_buf[2]=23;
hour16=time_buf[2]/10*16+time_buf[2]%10;
//Delay_ms(150);
write_ds1302(0x84,hour16);
}
break;
case 3:
{
time_buf[5]=time_buf[5]-1;
if(time_buf[5]==0)
time_buf[5]=7;
week16=time_buf[5]/10*16+time_buf[5]%10;
write_ds1302(0x8a,week16);
}
break;
case 4:
{
time_buf[3]=time_buf[3]-1;
if(time_buf[3]==0)
time_buf[3]=31;
day16=time_buf[3]/10*16+time_buf[3]%10;
//Delay_ms(150);
write_ds1302(0x86,day16);
}
break;

case 5:
{
time_buf[4]=time_buf[4]-1;
if(time_buf[4]==0)
time_buf[4]=12;
mon16=time_buf[4]/10*16+time_buf[4]%10;
//Delay_ms(150);
write_ds1302(0x88,mon16);
}
break;

case 6:
{
time_buf[6]=time_buf[6]-1;
if(time_buf[6]==0)
time_buf[6]=99;
year16=time_buf[6]/10*16+time_buf[6]%10;
//Delay_ms(150);
write_ds1302(0x8c,year16);
}
break;

default:break;
}
}

}
/*if((PIND&0X08)==0)
{

while(!(PIND&0X08));
beep();
time_buf[2]=time_buf[2]+1;
if(time_buf[2]==24)
time_buf[2]=0;
hour16=time_buf[2]/10*16+time_buf[2]%10;
write_ds1302(0x84,hour16);
}
if((PIND&0X10)==0)
{
while(!(PIND&0X10));
beep();
time_buf[1]=time_buf[1]+1;
if(time_buf[1]==60)
time_buf[1]=0;
min16=time_buf[1]/10*16+time_buf[1]%10;
write_ds1302(0x82,min16);
}*/

/*读取时间函数,并转化为十进制*/
void get_data()
{
uchar sec,min,hour,day,mon,week,year;
write_ds1302(0x8e,0x00);
write_ds1302(0x90,0xab);
sec=read_ds1302(0x81);
min=read_ds1302(0x83);
hour=read_ds1302(0x85);
day=read_ds1302(0x87);
mon=read_ds1302(0x89);
week=read_ds1302(0x8b);
year=read_ds1302(0x8d);
time_buf[0]=sec/16*10+sec%16;
time_buf[1]=min/16*10+min%16;
time_buf[2]=hour/16*10+hour%16;
time_buf[3]=day/16*10+day%16;
time_buf[4]=mon/16*10+mon%16;
time_buf[5]=week/16*10+week%16;
time_buf[6]=year/16*10+year%16;
}
/************温度-PWM转换函数******/
void Temp_PWM()
{
uint i;
if(TEMP<=0)
{
tempt=-1;
}
if(TEMP>0&&TEMP {
tempt=-1;
}
if(TEMP>=300&&TEMP {
tempt=256*(500-TEMP)/500;
}
if(TEMP>=500)
{
tempt=1;
beep(i);
}
}

/*******串口初始化********/
void uart0_Init(void)
{

UCSRB=0x00;
UCSRA=0X00;//发射器使能
/*设置帧格式*/
UCSRC|= (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);//工作模式 ,8位字符,1位停止位 // UCSRC=0x86;
/*设置波特率*/
UBRRL=(fosc/16/(baud+1))%256;
UBRRH=(fosc/16/(baud+1))/256;
/*接收器与发送器使能*/
UCSRB|=(1<<RXCIE)|(1<<RXEN)|(1<<TXEN);//UCSRB=0x98;
SREG|=BIT(7);
}
/*******发送数据函数********/
void UART0_send(uchar i)
{
uchar j;
while(!(UCSRA&(1<<UDRE)));
for(j=0;j<3;j++)
{UDR=i;}
}

/*主函数*/
void main(void)
{
uint i;
uint JISHU;
port_init();
init_ds1302();
lcd_init();
lcd_clr();
//SREG=0X80;
uart0_Init();
//INT0_init();
//max6675_init();
//PWM_Init_IO();
TIMER0_Init();
//timer1_init();
LCD_write_str(11,0,line1_data);
while(1)
{
if((PIND&0X40)==0)
{
Delay_ms(10);
if((PIND&0X04)==0)
{
while(!(PIND&0X04));
beep(100);
K1_FLAG++;
if(K1_FLAG>6)K1_FLAG=1;
}
KeyProcess();
}

if((PIND&0X40)==0X40)
{
MAX6675_conv();
temp_disp();
}

if((PIND&0X20)==0)
{
while(!(PIND&0X20));
beep(100);
write_ds1302(0x80,0x00);
write_ds1302(0x8e,0x80);
K1_FLAG=0;
Delay_ms(15);
}
get_data();
LCD_conv(time_buf[0],time_buf[1],time_buf[2],time_buf[3],time_buf[4],time_buf[5],time_buf[6]);
LCD_disp();
Temp_PWM();
PWM_control(tempt);
//SEED=TEMP/10%16+TEMP%10;
for(i=1;i<4;i++)
{UART0_send(show_data[i]);}
UART0_send(0x0d);
UART0_send(0x0a);
//Usart_PutString("温度");
}

}

/*********发送结束中断函数*******/
/*#pragma interrupt_handler UART0_TXD_vect:12
void UART0_TXD_vect(void)
{
SEED=TEMP;
UART0_send(SEED);
Usart_PutString("温度");
}*/
这是主程序,下面是有关PWM的程序
#include
#include
#define uint unsigned int
#define uchar unsigned char

uchar Rece[5]={0xD1,0xD1,0xD1,0xD1,0xD1};
uchar Spec[5]={0x82,0x82,0x82,0x82,0x82};
uchar Point[5]={0xfe,0xfd,0xfb,0xf7,0xef};
int cntA=0;

/********定时器0中断服务函数**********/

pragma interrupt_handler timer0_ovf:10

void timer0_ovf(void)

{

uchar temp;
temp=SREG;
TCNT0=0X00;//重装计数初值
cntA++;
switch(cntA)
{

case 1:
        TCNT0=Rece[0];
        PORTA&=~BIT(0);

      break;
case 2:
        TCNT0=0xff-Rece[0]+Spec[0];
        PORTA|=BIT(0);

      break;
case 3:
        TCNT0=Rece[1]; 
        PORTA&=Point[1];
      break;
case 4:
      TCNT0=0xff-Rece[1]+Spec[1];
      PORTA|=0xff-Point[1];
      break;
case 5:
      TCNT0=Rece[2]; 
      PORTA&=Point[2];
      break;
case 6:
      TCNT0=0xff-Rece[2]+Spec[3];
      PORTA|=0xff-Point[2];
      break;          
case 7:
      TCNT0=Rece[3];
      PORTA&=Point[3];
      break;
case 8:
      TCNT0=0xff-Rece[3]+Spec[3]; 
      PORTA|=0xff-Point[3];
      break;    
case 9:
      TCNT0=Rece[4];
      PORTA&=Point[4];
      break;
case 10:
      TCNT0=0xff-Rece[4]+Spec[4];
      PORTA|=0xff-Point[4];
      cntA=0;
}
SREG=temp; 

}

4个回答

congliu0913
congliu0913   2016.05.08 12:15

不知道你这个.o是自己编译的还是拷贝过来的,他不是说没定义那两个宏,我也是初学者,可能不正确。

qq_34860335
qq_34860335 上面贴出了全部程序,麻烦你帮我看看哪儿出错了。谢谢
一年多之前 回复
CSDNXIAOD
CSDNXIAOD   2016.05.08 12:22

c语言 解决汉诺塔问题
----------------------biu~biu~biu~~~在下问答机器人小D,这是我依靠自己的聪明才智给出的答案,如果不正确,你来咬我啊!

qq_28160773
qq_28160773   2016.05.08 12:33

请贴出全部代码!提示好像是出现了未定义变量!

qq_34860335
qq_34860335 出来了。麻烦你帮我看看哪儿有问题,谢谢
一年多之前 回复
qq_34860335
qq_34860335 贴出来了。麻烦你帮我看看哪儿有问题,谢谢
一年多之前 回复
havedream_one
havedream_one   2016.05.08 17:49

PWM_control(tempt);的定义没有看到啊

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!