| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 777 人关注过本帖
标题:[求助] 真是好難的問題
只看楼主 加入收藏
cjw23529
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-3-22
收藏
 问题点数:0 回复次数:3 
[求助] 真是好難的問題

不知道哪位好心的人可以幫幫我
我真的做不出來

以下是用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;
}

搜索更多相关主题的帖子: LCD module include AVR 
2007-06-07 10:06
cjw23529
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-3-22
收藏
得分:0 

以下是我測試時間的編程
但我不知道要如何讓時間顯示在LCD上
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

#include "LCD_Driver.h"


//function protoypes
void Timer0_Init();

//global variable
int min;
int sec;

int main()
{
char str[]="Hello, world!";
int i;

//initialize LCD module
LCD_init();

DDRA = 0xFF; //port A as output
DDRC = 0x7F; //port C as output except PC7

Timer0_Init(); //call the func to initialize the timer
sei();
int_start =1;
LCD_display('Time is %02d:%02d\r', min, sec);//要如何讓時間顯示在LCD上

x = sec;
input = PINC;
while(1)
{
if ( (input&0x80) != (PINC&0x80) )
{
input = PINC;
if (int_start ==1)
{
cli();
int_start = 0;
}
else
{
sei();
int_start = 1;
}
}

if (min!=PORTC)
{
PORTC = min;
}

if (x!=sec)
{
printf("Time is %02d:%02d\r", min, sec);//要如何讓時間顯示在LCD上
x = sec;
}
}
}

}
void Timer0_Init()
{
//set the frequency of timer0
OCR0 = 77;
TCCR0 |= (1<<COM00); //COM01:0=01 (toggle OC0)
TCCR0 |= (1<<WGM01); //WGM01:0=10 (select CTC)
TCCR0 |= ((1<<CS02)|(1<<CS01)|(1<<CS00));
//CS02:0=111 (N=1024)
TIMSK |= (1<<OCIE0); //enable timer OC interrupt
}

ISR(TIMER0_COMP_vect)
{
static int ms5;
static int half_sec;

PORTA ^= 0x01; //toggle PA0 every interrupt

ms5++;
if (ms5>100) //toggle PA1 every half sec
{
PORTA ^= 0x02;
ms5=0;
half_sec++;
}

if (half_sec>=2)
{
sec++;
half_sec = 0;
}

if (sec>=60)
{
min++;
sec = 0;
}

}

2007-06-07 19:43
Bonwe_PC
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2007-6-7
收藏
得分:0 
看不懂

不懂

2007-06-07 19:56
kinhwang
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2007-6-6
收藏
得分:0 

是C++吗

2007-06-07 20:08
快速回复:[求助] 真是好難的問題
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016316 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved