Em mới học về vdk. Sau 1 quá trình tự tìm tòi thì có thử làm 1 bài : dùng vdk atmega8, lcd 16x2, mạch em vẽ trên proteus.Nhưng đến khi viết code cho no' ( dung Codevision AVR ) biên dịch gặp một lỗi sau mà ko biết sửa :
Error: D:\hoctap\do`an\tu tim hieu\baitap_2\lcd.h(38), included from: baitap_2.c: missing '('
Các pro giúp em với Đây là code của nó:
/************************************************** ***
This program was produced by the
CodeWizardAVR V2.04.5b Evaluation
Automatic Program Generator
© Copyright 1998-2009 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 1/16/2010
Author : Freeware, for evaluation and non-commercial use only
Company :
Comments:
Chip type : ATmega8
Program type : Application
AVR Core Clock frequency: 1.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
************************************************** ***/
#include <mega8.h>
#include "lcd.h"
char str1[16] = "Do Thanh Hung^.^";
char str2[16] = "Lop DT1001- HPU ";
//===============================
void delay(unsigned int time)
{
while(time--)
{
int k = 121;
while(k--){}
}
}
//================================
void main()
{
unsigned int i;
LCD_Init();
for(i = 0; i<16;i++)
{
LCD_Position(0,i);
LCD_PutChar(str1[i]);
delay(150);
}
for(i = 0; i<16;i++)
{
LCD_Position(1,i);
LCD_PutChar(str2[i]);
delay(150);
}
delay(2000);
while(1){}
}
Còn đây là thư viện "lcd.h" dùng trên project trên.
/************************************************** **************************/
/* */
/* File: lcd.h */
/* Author: Vu Ha Linh, Automatic Control Deparment */
/* Ha Noi university of technology */
/* */
/************************************************** **************************/
/* */
/* Function: This module is a standard LCD (16x2) functions */
/* */
/* Input and Output parameters of those subroutines: */
/* void LCD_Init(void); */
/* void LCD_Position(unsigned char, unsigned char); */
/* void LCD_PutCmd(unsigned char); */
/* void LCD_PutChar(unsigned char); */
/* void LCD_PrString(char*); */
/* void LCD_Clear(void); */
/* void LCD_PrInteger(int); */
/* */
/* Note: Must be call LCD_Init() first at the begining of program */
/* */
/************************************************** **************************/
/* */
/* History: */
/* Version: */
/* Date Writer Remark */
/* */
/* 30-07-2006 Vu Ha Linh Creating the first version */
/* */
/* */
/************************************************** **************************/
/************************************************** ***************************
define Hardware address
************************************************** ***************************/
#define LCD_PORT P1
sbit LCD_RS = PD^2;
sbit LCD_RW = PD^3;
sbit LCD_EN = PD^4;
sbit LCD_D7 = PB^7;
#define ReadCommand {LCD_RS = 0; LCD_RW = 1;}
#define WriteCommand {LCD_RS = 0; LCD_RW = 0;}
#define WriteData {LCD_RS = 1; LCD_RW = 0;}
#define LatchData {LCD_EN = 1; LCD_EN = 0;}
/************************************************** **************************
define LCD command
************************************************** ***************************/
#define LCD_CLEAR 0x01 // Clear display
#define LCD_HOME 0x02 // return cursor and LCD to home position
#define LCD_OFF 0x08 // turn off display and cursor
#define LCD_DISPLAY_ON 0x0C // turn on display and turn off cursor
#define LCD_CURSOR_ON 0x0A // turn on cursor and turn off display
#define LCD_BLINK_CURSOR 0x0E // turn on display and blink cursor
#define LCD_FONT_8BIT 0x38 // set interace length: 8bits, 2 lines, font 5x8
#define LCD_FONT_4BIT 0x28 // set interace length: 4bits, 2 lines, font 5x8
#define LCD_MOVE_CURSOR 0x06 // Entry mode set: set increments mode, not shift (cursor)
#define LCD_MDRIGHT 0x1C // Move display to the right
#define LCD_MDLEFT 0x18 // Move display to the left
/************************************************** **************************
WaitReady function
Wait while LCD in execution time
************************************************** ***************************/
void WaitReady(void)
{
ReadCommand; // Set Read command mode
LCD_D7 = 1; // set bit 7 to 1 initially
while(LCD_D7){ // if bit 7 high lcd still busy
LCD_EN = 0;
LCD_EN = 1; // Read bit D7
}
}
/************************************************** **************************
LCD_PutCmd function
Write a control byte to LCD // viet' 1 ky tu dieu khien toi lcd
Input : control byte
************************************************** ***************************/
void LCD_PutCmd(unsigned char cmd)
{
WaitReady(); // Wait for LCD ready
WriteCommand; // set LCD to send mode
LCD_PORT = cmd; // Prepare to send
LatchData; // latch data out
}
/************************************************** **************************
LCD_PutChar function
Write a ASCII symbol to LCD
Input: ASCII symbol
************************************************** ***************************/
void LCD_PutChar(unsigned char ch)
{
WaitReady();
WriteData;
LCD_PORT = ch;
LatchData;
}
/************************************************** ***************************
LCD_PrString function
Write a string to LCD
Input: string
************************************************** ****************************/
void LCD_PrString(char *str)
{
while(*str!='\0')
{
LCD_PutChar(*str);
++str;
}
}
/************************************************** ***************************
LCD_Position function
Set the position of cursor on LCD // cai` vi tri con tro len lcd
Input: row, column
************************************************** ****************************/
void LCD_Position(unsigned char row, unsigned char col)
{
LCD_PutCmd( (1<<7)|(row<<6)|col );
}
/************************************************** ***************************
LCD_Clear function
Clear LCD
************************************************** ****************************/
void LCD_Clear()
{
LCD_PutCmd(LCD_CLEAR);
}
/************************************************** ***************************
LCD_Init function
Prepare for display content. Must be called at first chuan bi cho hien thi noi dung
************************************************** ****************************/
void LCD_Init()
{
// LCD_PutCmd(0x30); // Data length setting, 8 bits
// LCD_PutCmd(0x30); // Data length setting, 8 bits
// LCD_PutCmd(0x30); // Data length setting, 8bits
LCD_PutCmd(LCD_FONT_8BIT); // Function set: 8 bits mode and font: 5x8
// LCD_PutCmd(LCD_OFF); // Display and cursor OFF
// LCD_PutCmd(LCD_CLEAR); // Clear display
LCD_PutCmd(LCD_MOVE_CURSOR); // Entry mode set: Increment mode, not shift
LCD_PutCmd(LCD_DISPLAY_ON); // Display ON
// LCD_PutCmd(LCD_BLINK_CURSOR); // Blink cursor
}
/************************************************** **************************
LCD_PrInteger function
Display a integer decimal number on LCD
Input: a integer number
************************************************** ***************************/
void LCD_PrInteger(int num)
{
int temp;
unsigned char i, c[5];
temp = num;
if (temp != 0) {
if (temp < 0) {
LCD_PutChar('-');
temp = -temp;
}
i = 0;
while(temp){
c[i++] = temp%10;
temp /= 10;
}
while(i) LCD_PutChar(c[--i] + '0');
}
else LCD_PutChar('0');
}
/************************* END OF FILE *******************************/
Rất mong nhận các pác giúp đỡ. Em xin cam ơn nhìu.
Error: D:\hoctap\do`an\tu tim hieu\baitap_2\lcd.h(38), included from: baitap_2.c: missing '('
Các pro giúp em với Đây là code của nó:
/************************************************** ***
This program was produced by the
CodeWizardAVR V2.04.5b Evaluation
Automatic Program Generator
© Copyright 1998-2009 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 1/16/2010
Author : Freeware, for evaluation and non-commercial use only
Company :
Comments:
Chip type : ATmega8
Program type : Application
AVR Core Clock frequency: 1.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
************************************************** ***/
#include <mega8.h>
#include "lcd.h"
char str1[16] = "Do Thanh Hung^.^";
char str2[16] = "Lop DT1001- HPU ";
//===============================
void delay(unsigned int time)
{
while(time--)
{
int k = 121;
while(k--){}
}
}
//================================
void main()
{
unsigned int i;
LCD_Init();
for(i = 0; i<16;i++)
{
LCD_Position(0,i);
LCD_PutChar(str1[i]);
delay(150);
}
for(i = 0; i<16;i++)
{
LCD_Position(1,i);
LCD_PutChar(str2[i]);
delay(150);
}
delay(2000);
while(1){}
}
Còn đây là thư viện "lcd.h" dùng trên project trên.
/************************************************** **************************/
/* */
/* File: lcd.h */
/* Author: Vu Ha Linh, Automatic Control Deparment */
/* Ha Noi university of technology */
/* */
/************************************************** **************************/
/* */
/* Function: This module is a standard LCD (16x2) functions */
/* */
/* Input and Output parameters of those subroutines: */
/* void LCD_Init(void); */
/* void LCD_Position(unsigned char, unsigned char); */
/* void LCD_PutCmd(unsigned char); */
/* void LCD_PutChar(unsigned char); */
/* void LCD_PrString(char*); */
/* void LCD_Clear(void); */
/* void LCD_PrInteger(int); */
/* */
/* Note: Must be call LCD_Init() first at the begining of program */
/* */
/************************************************** **************************/
/* */
/* History: */
/* Version: */
/* Date Writer Remark */
/* */
/* 30-07-2006 Vu Ha Linh Creating the first version */
/* */
/* */
/************************************************** **************************/
/************************************************** ***************************
define Hardware address
************************************************** ***************************/
#define LCD_PORT P1
sbit LCD_RS = PD^2;
sbit LCD_RW = PD^3;
sbit LCD_EN = PD^4;
sbit LCD_D7 = PB^7;
#define ReadCommand {LCD_RS = 0; LCD_RW = 1;}
#define WriteCommand {LCD_RS = 0; LCD_RW = 0;}
#define WriteData {LCD_RS = 1; LCD_RW = 0;}
#define LatchData {LCD_EN = 1; LCD_EN = 0;}
/************************************************** **************************
define LCD command
************************************************** ***************************/
#define LCD_CLEAR 0x01 // Clear display
#define LCD_HOME 0x02 // return cursor and LCD to home position
#define LCD_OFF 0x08 // turn off display and cursor
#define LCD_DISPLAY_ON 0x0C // turn on display and turn off cursor
#define LCD_CURSOR_ON 0x0A // turn on cursor and turn off display
#define LCD_BLINK_CURSOR 0x0E // turn on display and blink cursor
#define LCD_FONT_8BIT 0x38 // set interace length: 8bits, 2 lines, font 5x8
#define LCD_FONT_4BIT 0x28 // set interace length: 4bits, 2 lines, font 5x8
#define LCD_MOVE_CURSOR 0x06 // Entry mode set: set increments mode, not shift (cursor)
#define LCD_MDRIGHT 0x1C // Move display to the right
#define LCD_MDLEFT 0x18 // Move display to the left
/************************************************** **************************
WaitReady function
Wait while LCD in execution time
************************************************** ***************************/
void WaitReady(void)
{
ReadCommand; // Set Read command mode
LCD_D7 = 1; // set bit 7 to 1 initially
while(LCD_D7){ // if bit 7 high lcd still busy
LCD_EN = 0;
LCD_EN = 1; // Read bit D7
}
}
/************************************************** **************************
LCD_PutCmd function
Write a control byte to LCD // viet' 1 ky tu dieu khien toi lcd
Input : control byte
************************************************** ***************************/
void LCD_PutCmd(unsigned char cmd)
{
WaitReady(); // Wait for LCD ready
WriteCommand; // set LCD to send mode
LCD_PORT = cmd; // Prepare to send
LatchData; // latch data out
}
/************************************************** **************************
LCD_PutChar function
Write a ASCII symbol to LCD
Input: ASCII symbol
************************************************** ***************************/
void LCD_PutChar(unsigned char ch)
{
WaitReady();
WriteData;
LCD_PORT = ch;
LatchData;
}
/************************************************** ***************************
LCD_PrString function
Write a string to LCD
Input: string
************************************************** ****************************/
void LCD_PrString(char *str)
{
while(*str!='\0')
{
LCD_PutChar(*str);
++str;
}
}
/************************************************** ***************************
LCD_Position function
Set the position of cursor on LCD // cai` vi tri con tro len lcd
Input: row, column
************************************************** ****************************/
void LCD_Position(unsigned char row, unsigned char col)
{
LCD_PutCmd( (1<<7)|(row<<6)|col );
}
/************************************************** ***************************
LCD_Clear function
Clear LCD
************************************************** ****************************/
void LCD_Clear()
{
LCD_PutCmd(LCD_CLEAR);
}
/************************************************** ***************************
LCD_Init function
Prepare for display content. Must be called at first chuan bi cho hien thi noi dung
************************************************** ****************************/
void LCD_Init()
{
// LCD_PutCmd(0x30); // Data length setting, 8 bits
// LCD_PutCmd(0x30); // Data length setting, 8 bits
// LCD_PutCmd(0x30); // Data length setting, 8bits
LCD_PutCmd(LCD_FONT_8BIT); // Function set: 8 bits mode and font: 5x8
// LCD_PutCmd(LCD_OFF); // Display and cursor OFF
// LCD_PutCmd(LCD_CLEAR); // Clear display
LCD_PutCmd(LCD_MOVE_CURSOR); // Entry mode set: Increment mode, not shift
LCD_PutCmd(LCD_DISPLAY_ON); // Display ON
// LCD_PutCmd(LCD_BLINK_CURSOR); // Blink cursor
}
/************************************************** **************************
LCD_PrInteger function
Display a integer decimal number on LCD
Input: a integer number
************************************************** ***************************/
void LCD_PrInteger(int num)
{
int temp;
unsigned char i, c[5];
temp = num;
if (temp != 0) {
if (temp < 0) {
LCD_PutChar('-');
temp = -temp;
}
i = 0;
while(temp){
c[i++] = temp%10;
temp /= 10;
}
while(i) LCD_PutChar(c[--i] + '0');
}
else LCD_PutChar('0');
}
/************************* END OF FILE *******************************/
Rất mong nhận các pác giúp đỡ. Em xin cam ơn nhìu.
Comment