为什么16F84A可以 16F877A 不可以
为什么16F84A可以 16F877A 不可以该程序是显示LCD(4*16)的 其中lcd.c 是利用PICC的sample程序
#include <pic.h>
#include "lcd.h"
#include "delay.h"
__CONFIG (WDTDIS & PWRTEN & HS );
void delay(char,char);
void lcd_UserInfoDispaly(void);
void ad_Conver(void);
void main(void)
{
int kk;
PORTA=0x00;
PORTB=0x00;
TRISB=0x00; //LCD data0~7 output mode
TRISA=0xF8; //LCD Control output RS,R/W,EN
DelayMs(500);
lcd_init(); //initialise the LCD
lcd_UserInfoDispaly();
while(1)
{
;
}
}
void delay(char x,char y)
{
char z;
do{
z=y;
do{;}while(--z);
}while(--x);
}
void lcd_UserInfoDispaly(void)
{
int i;
lcd_goto(0x00);
lcd_puts("ABCDEF"); //Display string in LCD*/
lcd_goto(0x42);
lcd_puts("ABCDEF TEST");//Display char in LCD
lcd_goto(0x14);
lcd_puts("AAA-001");//Display char in LCD
lcd_goto(0x58);
lcd_puts("Ver1.00");//Display char in LCD
for(i=100;i>0;i--){
DelayMs(500);
}
lcd_clear();
lcd_goto(0x00);
lcd_puts("Frequency:"); //Display string in LCD*/
lcd_goto(0x0B);
lcd_puts("Volt:"); //Display string in LCD*/
lcd_goto(0x47);
lcd_puts("Hz"); //Display string in LCD*/
lcd_goto(0x4E);
lcd_puts("V"); //Display string in LCD*/
lcd_goto(0x50);
lcd_puts("Design:ABCDEF/HI"); //Display string in LCD*/
}
/*
* LCD interface example
* Uses routines from delay.c
* This code will interface to a standard LCD controller
* like the Hitachi HD44780. It uses it in 8 bit mode, with
* the hardware connected as follows (the standard 14 pin
* LCD connector is used):
*
* PORTB bits 0-7 are connected to the LCD data bits 0-7
* PORTC bit 0 is connected to the LCD RS input (register select)
* PORTC bit 2 is connected to the LCD EN bit (enable)
*
* To use these routines, set up the port I/O (TRISB, TRISC) then
* call lcd_init(), then other routines as required.
*
*/
#include <pic.h>
#include "lcd.h"
#include "delay.h"
static bit LCD_RS @ ((unsigned)&PORTA*8+0); // Register select
static bit LCD_RW @ ((unsigned)&PORTA*8+1); // Read/write select
static bit LCD_EN @ ((unsigned)&PORTA*8+2); // Enable
/* read busy singal from the LCD */
void lcd_busy(void)
{
inti=1;
while(i)
{
TRISB=0xFF;
LCD_RS=0;
LCD_RW=1;
LCD_EN=1;
i=RB7;
LCD_EN=1;
}
LCD_RW=0;
TRISB=0x00;
}
/* write a byte to the LCD in 8 bit mode */
void lcd_write(unsigned char c)
{
lcd_busy();
PORTB=c;
LCD_EN=1;
LCD_EN=1;
LCD_EN=1;
LCD_EN= 0;
DelayMs(15);
PORTB=0x00;
}
/*
*Clear and home the LCD
*/
void lcd_clear(void)
{
LCD_RS = 0;
lcd_write(0x01);
DelayMs(12);
}
/* write a string of chars to the LCD */
void lcd_puts(const char *s)
{
LCD_RS= 1; // write characters
while(*s)
lcd_putch(*s++);
}
/* write one character to the LCD */
void lcd_putch(char c)
{
LCD_RS= 1; // write characters
PORTB=c;
LCD_EN= 1;
LCD_EN= 1;
LCD_EN= 1;
LCD_EN= 0;
DelayMs(15);
PORTB=0x00;
}
/*
* Go to the specified position
*/
void lcd_goto(unsigned char pos)
{
LCD_RS= 0;
lcd_write(0x80+pos);
}
/* initialise the LCD - put into 8 bit mode */
void lcd_init(void)
{
LCD_RS= 0; // write control bytes
PORTB=0x30;
LCD_EN= 1;
LCD_EN= 1;
LCD_EN= 1;
LCD_EN= 0;
DelayMs(5);
PORTB=0x30;
LCD_EN= 1;
LCD_EN= 1;
LCD_EN= 1;
LCD_EN= 0;
DelayUs(100);
PORTB=0x30;
LCD_EN= 1;
LCD_EN= 1;
LCD_EN= 1;
LCD_EN= 0;
lcd_write(0x38); // 8 bit mode, 1/16 duty, 5x7 font
lcd_write(0x08); // display off
lcd_write(0x0F); // display on, blink curson on
lcd_write(0x06); // entry mode
}
/*
* Delay functions
* See delay.h for details
*
* Make sure this code is compiled with full optimization!!!
*/
#include "delay.h"
void
DelayMs(unsigned char cnt)
{
#if XTAL_FREQ <= 2MHZ
do {
DelayUs(996);
} while(--cnt);
#endif
#if XTAL_FREQ > 2MHZ
unsigned char i;
do {
i = 4;
do {
DelayUs(250);
} while(--i);
} while(--cnt);
#endif
}
/*
* LCD interface header file
* See lcd.c for more info
*/
/* read busy singal from the LCD */
extern void lcd_busy(void);
/* write a byte to the LCD in 4 bit mode */
extern void lcd_write(unsigned char);
/* Clear and home the LCD */
extern void lcd_clear(void);
/* write a string of characters to the LCD */
extern void lcd_puts(const char * s);
/* Go to the specified position */
extern void lcd_goto(unsigned char pos);
/* intialize the LCD - call before anything else */
extern void lcd_init(void);
extern void lcd_putch(char);
/* Set the cursor position */
//#define lcd_cursor(x) lcd_write(((x)&0x7F)|0x80)
/*
* Delay functions for HI-TECH C on the PIC
*
* Functions available:
*DelayUs(x) Delay specified number of microseconds
*DelayMs(x) Delay specified number of milliseconds
*
* Note that there are range limits: x must not exceed 255 - for xtal
* frequencies > 12MHz the range for DelayUs is even smaller.
* To use DelayUs it is only necessary to include this file; to use
* DelayMs you must include delay.c in your project.
*
*/
/* Set the crystal frequency in the CPP predefined symbols list in
HPDPIC, or on the PICC commmand line, e.g.
picc -DXTAL_FREQ=4MHZ
or
picc -DXTAL_FREQ=100KHZ
Note that this is the crystal frequency, the CPU clock is
divided by 4.
* MAKE SURE this code is compiled with full optimization!!!
*/
#ifndef XTAL_FREQ
#define XTAL_FREQ 4MHZ/* Crystal frequency in MHz */
#endif
#define MHZ *1000L /* number of kHz in a MHz */
#define KHZ *1 /* number of kHz in a kHz */
#if XTAL_FREQ >= 12MHZ
#define DelayUs(x) { unsigned char _dcnt; \
_dcnt = (x)*((XTAL_FREQ)/(12MHZ)); \
while(--_dcnt != 0) \
continue; }
#else
#define DelayUs(x) { unsigned char _dcnt; \
_dcnt = (x)/((12MHZ)/(XTAL_FREQ))|1; \
while(--_dcnt != 0) \
continue; }
#endif
extern void DelayMs(unsigned char); 关比较、关AD
页:
[1]