不知道哪位好心的人可以幫幫我
我真的做不出來
以下是用AVR做的
包含LCD module (LCD 可顯示兩行) 這個部分已經做出來了 一定正確
題目
按A開始計算時間從00:00.0開始 到99:59.9
再按一次A時間會停止 如時間跑到35:11.9時 按A會停在35:11.9再按一次A會從35:11.9 開始(都顯示在第一行)
按B 時間會停止在第二行 但第一行仍然在計時
按D 會把所有時間歸0 就是回到00:00.0的時間
以下是LCD module 的編程(一定正確的)
這個是LCD_Ddriver.c
#include <avr/io.h>
#include <util/delay.h>
#include "LCD_Driver.h"
//internal funciton prototypes
void LCD_init();
void LCD_cmd_nibble(char c);
void LCD_dat_nibble(char c);
/* to write the higer nibble of a command to LCD module */
void LCD_cmd_nibble(char c)
{
    //output the higher nibble to LCD with RS=0,RD=0,EN=0
    LCD_PORT = c & 0xF0;
    LCD_PORT = LCD_PORT | (1<<EN);
    _delay_us(1);            //EN=1 for at least .5us
    LCD_PORT = LCD_PORT & (~(1<<EN));
    _delay_us(1);            //at least 1us for each cycle
}
/* to write the higer nibble of a data byte to LCD module */
void LCD_dat_nibble(char c)
{
    //output the higher nibble to LCD with RS=0,RD=0,EN=0
    LCD_PORT = c & 0xF0;
    LCD_PORT = LCD_PORT | (1<<RS);    //for writing data
    LCD_PORT = LCD_PORT | (1<<EN);
    _delay_us(1);            //EN=1 for at least .5us
    LCD_PORT = LCD_PORT & (~(1<<EN));
    _delay_us(1);            //at least 1us for each cycle
}
/* to write a command to LCD module */
void LCD_command(char cmd)
{
    LCD_cmd_nibble(cmd);    //higher nibble
    LCD_cmd_nibble(cmd<<4);    //lower nibble
    _delay_ms(2);        //max cmd processing time: 1.64ms
}
/* to display a character in LCD module at the current position*/
void LCD_display(char character)
{
    LCD_dat_nibble(character);    //higher nibble
    LCD_dat_nibble(character<<4);    //lower nibble
    _delay_us(50);        //max data processing time: 40us
}
/* to initialize the LCD module */
void LCD_init()
{
    _delay_ms(15);
LCD_DDR = 0xFF; //LCD port as output
    LCD_cmd_nibble(0x30);//set the LCD module as 8-bit mode three times
    _delay_ms(5);
    LCD_cmd_nibble(0x30);
    _delay_ms(5);
    LCD_cmd_nibble(0x30);
    _delay_ms(5);
    LCD_cmd_nibble(0x20);    //set the LCD module as 4-bit mode
    _delay_ms(5);
    //from now on the LCD module works as 4-bit mode
    //write cmd as normal
LCD_command(0x28);//4-bit mode, 2-line dispay, 5x7 dot char font
LCD_command(0x08);    //display OFF
LCD_command(0x01);    //clear dispay
LCD_command(0x06);    //cursor increment, no shift
LCD_command(0x0F);    //dispay ON with cursor on and blinking
}
這個是LCD_Ddriver.h
#ifndef LCD_DRIVER_H
#define LCD_DRIVER_H
#define LCD_PORT        PORTB
#define LCD_DDR        DDRB
#define RS            0    //pin0
#define RD            1    //pin1
#define EN            2    //pin2
                    //pin3: unused
                    //pin4-pin7: 4-bit data bus 
/******  LCD funciton prototypes *********/
void LCD_init();            //must be called before the LCD module is usable
void LCD_command(char cmd);    //write a command to LCD module
void LCD_display(char ch);    //display a character in LCD module
                    //at the current position set by LCD_command()
#endif
以下就是要做的主程式
我只會把一些字顯示在LCD上 但不會計時
以下就是顯示在LCD上的字的編程
#include <avr/io.h>
#include <util/delay.h>
#include "LCD_Driver.h"
int main()
{
    char str[]="Hello, world!";
    int i;
    //initialize LCD module
    LCD_init();
    
    //write character to LCD to display    
    LCD_display('A');
    //move cursor to 2nd line, 1st position and then display characters
    LCD_command(0xC0);
    i=0;
    while(str[i])
    {
        LCD_display(str[i++]);
    }
    while(1);
    return 0;
}

 
											





 
	    