- #include "1602.h"
- #include "delay.h"
- #include <intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define _NOP() _nop_()
- sbit RS = P2^4; //定義端口
- sbit RW = P2^5;
- sbit EN = P2^6;
- #define DataPort P0
- #define DataPIN P0
- #define DataDir P0
- #define CLR_RS (RS=0)
- #define SET_RS (RS=1)
- #define CLR_RW (RW=0)
- #define SET_RW (RW=1)
- #define CLR_EN (EN=0)
- #define SET_EN (EN=1)
- LcdReset(); //LCD1602初始化
- DelayMs(10);
- sprintf(temp,"1111111111111111");//更新顯示
- DispStr(0,0,(unsigned char *)temp);//打印顯示
- sprintf(temp,"1111111111111111");//更新顯示
- DispStr(0,1,(unsigned char *)temp);//打印顯示
- /***********************************************
- 函數名稱:DispStr
- 功 能:讓液晶從某個位置起連續顯示一個字符串
- 參 數:x--位置的列坐標
- y--位置的行坐標
- ptr--指向字符串存放位置的指針
- 返回值 :無
- ***********************************************/
- void DispStr(uchar x,uchar y,uchar *ptr)
- {
- uchar *temp;
- uchar i,n = 0;
-
- temp = ptr;
- while(*ptr++ != '\0') n++; //計算字符串有效字符的個數
-
- for (i=0;i<n;i++)
- {
- if((temp[i]&0x30)==0x30)temp[i]=temp[i]&0x36;//**All notes can be deleted and modified**//
- Disp1Char(x++,y,temp[i]);
- if (x == 0x10)
- {
- break;
- }
- }
- }
- /*******************************************
- 函數名稱:DispNchar
- 功 能:讓液晶從某個位置起連續顯示N個字符
- 參 數:x--位置的列坐標
- y--位置的行坐標
- n--字符個數
- ptr--指向字符存放位置的指針
- 返回值 :無
- *******************************************/
- void DispNChar(uchar x,uchar y, uchar n,uchar *ptr)
- {
- uchar i;
-
- for (i=0;i<n;i++)
- {
- Disp1Char(x++,y,ptr[i]);
- if (x == 0x10)
- {
- x = 0;
- y ^= 1; //異或操作 換行
- }
- }
- }
- /*******************************************
- 函數名稱:LocateXY
- 功 能:向液晶輸入顯示字符位置的坐標信息
- 參 數:x--位置的列坐標
- y--位置的行坐標
- 返回值 :無
- ********************************************/
- void LocateXY(uchar x,uchar y)
- {
- uchar temp;
- temp = x&0x0f;
- y &= 0x01;
- if(y) temp |= 0x40; //如果在第2行
- temp |= 0x80;
- LcdWriteCommand(temp,1);
- }
- /*******************************************
- 函數名稱:Disp1Char
- 功 能:在某個位置顯示一個字符
- 參 數:x--位置的列坐標
- y--位置的行坐標
- data--顯示的字符數據
- 返回值 :無
- ********************************************/
- void Disp1Char(uchar x,uchar y,uchar data1)
- {
- LocateXY( x, y );
- LcdWriteData( data1 );
- }
- /*******************************************
- 函數名稱:LcdReset
- 功 能:對1602液晶模塊進行復位操作
- 參 數:無
- 返回值 :無
- ********************************************/
- void LcdReset(void)
- {
- DataDir = 0xFF; //數據端口設為輸出狀態
- LcdWriteCommand(0x38, 0); //規定的復位操作
- DelayMs(5);
- LcdWriteCommand(0x38, 0);
- DelayMs(5);
- LcdWriteCommand(0x38, 0);
- DelayMs(5);
- LcdWriteCommand(0x38, 1); //顯示模式設置
- LcdWriteCommand(0x08, 1); //顯示關閉
- LcdWriteCommand(0x01, 1); //顯示清屏
- LcdWriteCommand(0x06, 1); //寫字符時整體不移動
- LcdWriteCommand(0x0c, 1); //顯示開,不開游標,不閃爍
- }
- /*------------------------------------------------
- 清屏函數
- ------------------------------------------------*/
- void LcdClear(void)
- {
- LcdWriteCommand(0x01,1);
- DelayMs(5);
- }
- /*******************************************
- 函數名稱:LcdWriteCommand
- 功 能:向液晶模塊寫入命令
- 參 數:cmd--命令,
- chk--是否判忙的標志,1:判忙,0:不判
- 返回值 :無
- ********************************************/
- void LcdWriteCommand(uchar cmd,uchar chk)
- {
- if (chk) WaitForEnable(); // 檢測忙信號?
-
- CLR_RS;
- CLR_RW;
- _NOP();
- DataPort = cmd; //將命令字寫入數據端口
- _NOP();
-
- SET_EN; //產生使能脈沖信號
- _NOP();
- _NOP();
- CLR_EN;
- }
- /*******************************************
- 函數名稱:LcdWriteData
- 功 能:向液晶顯示的當前地址寫入顯示數據
- 參 數:data--顯示字符數據
- 返回值 :無
- ********************************************/
- void LcdWriteData( uchar data1 )
- {
- WaitForEnable(); //等待液晶不忙
- SET_RS;
- CLR_RW;
- SET_EN;
-
- _NOP();
- DataPort = data1; //將顯示數據寫入數據端口
- _NOP();
- //產生使能脈沖信號
- _NOP();
- _NOP();
- CLR_EN;
- }
- /*******************************************
- 函數名稱:WaitForEnable
- 功 能:等待1602液晶完成內部操作
- 參 數:無
- 返回值 :無
- ********************************************/
- void WaitForEnable(void)
- {
- unsigned int later=0;
- DataPort=0xff;
- CLR_RS;
- SET_RW;
- _NOP();
- SET_EN;
- _NOP();
- _NOP();
- while((DataPIN&Busy)!=0);
- while(((DataPIN&0x80)!=0)&&(later<1000)) //檢測忙標志
- {
- DelayUs2x(2);
- later++;
- }
- CLR_EN;
- DataDir|=0xFF; //將P4口切換為輸出狀態
- }
復制代碼 compiling 1602.c...
1602.C(25): error C231: 'LcdReset': redefinition
1602.C(26): error C141: syntax error near '10'
1602.C(26): error C231: '_DelayMs': redefinition
1602.C(27): error C141: syntax error near '<string>'
1602.C(28): error C141: syntax error near '0'
1602.C(28): error C132: 'temp': not in formal parameter list
1602.C(28): error C141: syntax error near ')'
1602.C(29): error C141: syntax error near '<string>'
1602.C(29): error C132: '_sprintf': not in formal parameter list
1602.C(30): error C141: syntax error near '0'
1602.C(30): error C132: 'DispStr': not in formal parameter list
1602.C(30): error C141: syntax error near 'temp'
1602.C(30): error C132: 'temp': not in formal parameter list
1602.C(41): error C132: '_DispStr': not in formal parameter list
1602.C(41): error C141: syntax error near '{'
1602.C(42): error C132: 'temp': not in formal parameter list
1602.C(43): error C132: 'i': not in formal parameter list
1602.C(43): error C244: 'n': can't initialize, bad type or class
1602.C(43): error C132: 'n': not in formal parameter list
1602.C(45): error C244: 'temp': can't initialize, bad type or class
1602.C(45): error C202: 'ptr': undefined identifier
1602.C(45): error C132: 'temp': not in formal parameter list
1602.C(46): error C141: syntax error near 'while'
1602.C(46): error C141: syntax error near '++', expected ')'
1602.C(46): error C129: missing ';' before '++'
1602.c - 25 Error(s), 0 Warning(s).
我現在在學習這個18b20測溫 1602顯示 然后這是網上找的程序
錯誤這么多 怎么搞啊
這是缺了聲明函數還是啥?
|