我們有一個項目,我們完成了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