- #include <p18f4520.h> //納入微控制器定義檔
- #include <delays.h> //納入時間延遲函式庫定義檔
- #include "evm_lcd.h" //納入LCD函式庫定義檔
- #include <stdio.h>
- // 設定微處理器相關結構位元
- #pragma config OSC=HS, BOREN=OFF, BORV = 2, PWRT=ON, WDT=OFF, LVP=OFF
- // 定義時序頻率
- #define OSC_CLOCK 10
- // 宣告時間延遲函式原型
- void delay_ms(long A);
- void main() {
- int i;
- OpenLCD(); // 初始化LCD模組
- WriteCmdLCD( 0x01 ); // 清除LCD顯示資料
- LCD_Set_Cursor( 0, 0 ); // 顯示位置回至第0行第0格
- delay_ms(1); // 時間延遲
- putrsLCD("Welcome to PIC"); // 顯示資料
- LCD_Set_Cursor( 1, 0 ); // 顯示位置調至第1行第0格
- delay_ms(1); // 時間延遲
- putrsLCD("Micro-Controller");// 顯示資料
- delay_ms(1000);
- WriteCmdLCD( 0x01 ); // 清除LCD顯示資料
- for (i=0;i<100;i++)
- {
- char buf[10];
- //WriteCmdLCD( 0x01 );
- LCD_Set_Cursor( 0, 0 );
- delay_ms(1000);
- sprintf(buf,"%d",i);
- putsLCD(buf);
- }
- Sleep(); // 進入睡眠省電模式
- while(1); // 永久迴圈
- }
- // 時間延遲函式
- void delay_ms(long A) {
- //This function is only good for OSC_CLOCK higher than 4MHz
- long i;
- int us2TCY;
- us2TCY=(10*OSC_CLOCK)>>2;
- for(i=0;i<A;i++) Delay100TCYx(us2TCY);
- }
2013年10月22日 星期二
PIC LCD顯示 1-100 簡易範例
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言