英锐恩单片机论坛,Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流

 找回密码
 立即注册
搜索
电子烟方案单片机单片机开发深圳单片机开发
单片机方案国产单片机8位单片机电子烟方案开发
查看: 3965|回复: 1
打印 上一主题 下一主题

为什么16F84A可以 16F877A 不可以

[复制链接]
跳转到指定楼层
1#
发表于 2009-4-25 14:45:24 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
为什么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)
{
int  i=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);
2#
 楼主| 发表于 2009-4-25 14:45:35 | 只看该作者
关比较、关AD
回复 支持 反对

使用道具 举报

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

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|公司首页|Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流 ( 粤ICP备09008620号 )

GMT+8, 2024-11-24 03:36 , Processed in 0.051993 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表