2738|1

82

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

帮朋友问题 关于LCD显示的 [复制链接]

不知道哪位好心的人可以幫幫我
我真的做不出來
以下是用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
#include
#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< _delay_us(1);   //EN=1 for at least .5us
LCD_PORT = LCD_PORT & (~(1< _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< LCD_PORT = LCD_PORT | (1< _delay_us(1);   //EN=1 for at least .5us
LCD_PORT = LCD_PORT & (~(1< _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
#include
#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)
{
  LCD_display(str[i++]);
}
while(1);
return 0;
}

最新回复

以下是我測試時間的編程 但我不知道要如何讓時間顯示在LCD上 #include #include #include #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  详情 回复 发表于 2007-6-8 00:03
点赞 关注

回复
举报

71

帖子

0

TA的资源

一粒金砂(初级)

沙发
 
以下是我測試時間的編程
但我不知道要如何讓時間顯示在LCD上
#include
#include
#include

#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<         TCCR0 |= (1<         TCCR0 |= ((1<                                                         //CS02:0=111 (N=1024)
        TIMSK |= (1< }

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;
        }

}
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表