我们有一个项目,我们完成了60%的程序,但我们遇到了2个问题 我们的第一个问题是让发动机应该冷却5秒,然后 应该加热10秒,然后它应停止像它不会再次除非我在交换机上再次合作microC嵌入式系统中的一些错误
这是我们的项目: -
开关0控制车(0无操作)操作(1号车运行) 我们用这部分完成
开关1用于安全带: 我们正在与这部分
开关2是门做: 我们正在与这部分
在这一部分,我们让做了,但问题应该只做过1次! 但因为我们有一个while循环永远不会停止! 那我们该怎么办?!
而汽车运行时,发动机将采取15S被加热: 在开始 - >“HH”将LCD上显示,加热器导致在应用电路板上将上,并在 同时马达将向前运行5秒钟以使其冷却。 SO'HN'将显示在液晶屏上。 之后,发动机将需要加热10秒钟。
这是我们不能做到的第二个问题! 我们考虑在另一个循环内部的一个循环内部制作一个循环,但它会 不起作用,我们也尝试通过定时器和它内部的另一个定时器来做到这一点! 我们应该通过定时器或中断我们不能使用延迟
我们将有4个LED代表燃料水平。 每隔10s一个led将关闭。 当最后一个指示灯仍然亮起时,会出现警告: (1)LCD上第2行显示'FL''。 如果开关3接通,燃油将会充满,否则汽车将关闭。
这是我们的代码!
sbit LCD_RS at RA1_bit;
sbit LCD_RW at RA2_bit;
sbit LCD_EN at RA3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_RS_Direction at TRISA1_bit;
sbit LCD_RW_Direction at TRISA2_bit;
sbit LCD_EN_Direction at TRISA3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
int i;
sbit LED0 at RC0_bit;
sbit LED1 at RC1_bit;
sbit LED2 at RC2_bit;
sbit LED4 at RC4_bit;
sbit LED5 at RC5_bit;
sbit LED6 at RC6_bit;
sbit LED7 at RC7_bit;
sbit Switch0 at RB0_bit;
sbit Switch1 at RB1_bit;
sbit Switch2 at RB2_bit;
sbit Switch3 at RB3_bit;
int Num;
void Move_Delay() { // Function used for text moving
Delay_ms(1000); // You can change the moving speed here
}
void main() {
ADCON1 = 0X06; //a port as ordinary i/o.
TRISA=0X00; //a port as output.
TRISD=0X00; //d port as output.
TRISC=0X00;
TRISB=0X0F;
PORTC = 0b00000000;
OPTION_REG = 0xD2;
Num = 0; //clear the number of overflows
OPTION_REG = 0x82; //Timer, Internal cycle clock (Fosc/4)
//Prescaler is assigned to the TMR0 timer/counter
//Prescaler (1:128) is assigned to the timer TMR0
TMR0 = 56; //Timer T0 counts from 39 to 255
INTCON.T0IF=0;
Lcd_Init(); // Initialize LCD
Delay_ms(200);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
LED0 = 0;
LED1= 0;
do {
if (Switch0)
{
Delay_ms(200); // pause 20 mS
if(INTCON.T0IF) //check for TMR0 register overflow
{
Num ++; // overflow causes Num to be incremented by 1
TMR0 = 56; // TMR0 returns to its initial value
INTCON.T0IF = 0 ; // Bit T0IF is cleared
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,2,"cooling");
}
if(Num ==108)
{
Lcd_Cmd(_LCD_CLEAR);
LED0=~LED0;
Lcd_Out(1,2,"heater ");
Delay_ms(1000);
}
}
else
Lcd_Cmd(_LCD_CLEAR);
if (switch1)
{
Delay_ms(20); // pause 20 mS
Lcd_Out(2,1,"BO");
LED1=0;
}
else
{
if(INTCON.T0IF) //check for TMR0 register overflow
{
Num ++; // overflow causes Num to be incremented by 1
TMR0 = 39; // TMR0 returns to its initial value
INTCON.T0IF = 0 ; // Bit T0IF is cleared
/*Lcd_Cmd(_LCD_CLEAR);*/
Lcd_Out(2,1,"BF ");
LED1=~LED1;
}
if(Num == 108)
{ //after 108 overflows
Num = 0;
}
}
if (switch2)
{
Lcd_Out(2,5,"DO");
LED2=0;
}
else
{
if(INTCON.T0IF) //check for TMR0 register overflow
{
Num ++; // overflow causes Num to be incremented by 1
TMR0 = 39; // TMR0 returns to its initial value
INTCON.T0IF = 0 ; // Bit T0IF is cleared
/*Lcd_Cmd(_LCD_CLEAR);*/
Lcd_Out(2,5,"DF");
LED2=~LED2;
}
if(Num == 108)
{ //after 108 overflows
Num = 0;
}
}
//这是错误的
if(switch3)
{
Delay_ms(500); // Clear display
//Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1," FFFFFFFFFF"); // Write text in first row
Delay_ms(500);
for(i=0; i<15; i++) { // Move text to the right 7 times
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
if(i==14)
{
Lcd_Cmd(_LCD_CLEAR); // Cursor off
Lcd_Out(1,1," warning !! ");
Delay_ms(1000);
}
}
}
} while(1);
}
我很抱歉没有解释太多,但我在问题的同一部分解释了我们项目中的问题。我给出了问题,并在每个部分上面解释我们的问题。我再次解释了第一个问题,这个问题的代码是我们代码中的第一部分,它是一个计时器,包括加热和冷却过程。第二部分我解释说,我不知道如何做,所以我尝试了很多时间,这是我们的尝试之一。所以我需要知道什么是想法。 – student 2014-12-14 05:35:40
在延迟的情况下,我们可以使用它,但不是主要部分,例如,如果我们需要将led灯打开10,我们应该使用计时器不会延迟。我们感谢您的工作,但您的代码不起作用。谢谢 。 – student 2014-12-14 05:41:36
代码不应该“工作”。这是一个示例,显示主循环如何并行处理所有进程,而不是串行处理。 – 2014-12-14 18:12:08