//
/**
* Title: LCD DEMO for use in Lab 2 tutorial
* C File lcddemo.c
* Platform: PICmicro PIC16F877A @ 4 Mhz
* Written by: GBM
*
* Date: 01/10/2018
*
* Function: A sample c file to show how to use the LCD display onboard
* the PIC DIP-40 board.
*
*/
// CONFIG
#pragma config FOSC = XT // Oscillator Selection bits (XT oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>
#include <stdio.h> // Include Standard I/O header file
#include "ee302lcd.h" // Include LCD header file. This file must be in same
// directory as source main source file.
#ifndef _XTAL_FREQ
// Unless already defined assume 4MHz system frequency
// This definition is required to calibrate the delay functions, __delay_us() and __delay_ms()
#define _XTAL_FREQ 4000000
#endif
// Definitions____________________________________________________________
#define CLOSED 0 // Define switch action "Closed" as 0
#define SW1 RB0 // Assign Label SW1 to PortB bit 0 (RB0)
#define SW2 RB1 // Assign Label SW2 to PortB bit 1 (RB1)
#define VALUE1 123
#define VALUE2 456
// globals _____________________________________________________
unsigned char gOutString[16]; //
// Prototypes_____________________________________________________________
void setup(void); // Declare setup function
void loop(void); // Declare loop function
void data2LCD(void); // Declare data to LCD function
void lcdTitle(void); // Declare title to LCD function
void clear_outString(void); // Declare outString clear function
//Main program
void main(void)
{
setup(); // Call initialisation
lcdTitle(); // Call LCDTitle
//Superloop
for(;;)
{
loop(); // Write data to LCD
}
}
void setup(void)
{
Lcd8_Init(); // Required initialisation of LCD to 8-bit mode
TRISB=0x03; // Set PORTB bit 0 and 1 as inputs
}
void loop(void)
{
data2LCD();
}
void data2LCD(void)
{
if (SW1 == CLOSED) // If SW1 closed then
{
Lcd8_Clear(); //clear LCD display
clear_outString(); //clear outString array
sprintf(gOutString,"Int Value1 is"); //define string as "Int Value is"
Lcd8_Write_String(gOutString); //print string to LCD
Lcd8_Set_Cursor(2,1); //select line 2 of LCD
sprintf(gOutString," %d",VALUE1); //define intvalue as a char in outString
Lcd8_Write_String(gOutString); //print string to LCD
}
if (SW2 == CLOSED) // If SW2 closed then
{
// Modulus used to help convert integer to ASCII character
Lcd8_Clear(); //clear LCD display
clear_outString(); //clear outString array
sprintf(gOutString,"Int Value2 is"); //define string as "Int Value is"
Lcd8_Write_String(gOutString); //print string to LCD
Lcd8_Set_Cursor(2,7); //select line 2 of LCD
clear_outString(); //clear outString array
gOutString[0] = (VALUE2/100)%10 + 48; // add 48 (0x30) to remainder to offset to character in Ascii table.
gOutString[1] = (VALUE2/10)%10 + 48;
gOutString[2] = (VALUE2/1)%10 + 48;
Lcd8_Write_String(gOutString);
}
}
void lcdTitle(void)
{
Lcd8_Write_String("HAITAO"); // print "LCD Demo" on line 1 of LCD
Lcd8_Set_Cursor(2,1); // select line 2
Lcd8_Write_String("DA SB"); // print "LCD Demo" on line 2 of LCD
}
void clear_outString(void)
{
int i;
for (i=0; i<16; i++)
{
gOutString[i] = 0x00;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
EE302 - Lab 02
共39个文件
xml:5个
i:4个
p1:4个
需积分: 5 0 下载量 165 浏览量
2022-10-06
13:31:35
上传
评论
收藏 153KB ZIP 举报
温馨提示
EE302 - Lab 02
资源详情
资源评论
资源推荐
收起资源包目录
LAB2.X.zip (39个子文件)
LAB2.X
ee302lcd.h 3KB
main.c 3KB
.DS_Store 6KB
dist
default
production
LAB2.X.production.elf 14KB
doprnt.i 11KB
__eeprom.p1 29KB
__eeprom.i 46KB
LAB2.X.production.lst 148KB
LAB2.X.production.sdb 5KB
LAB2.X.production.sym 9KB
LAB2.X.production.map 21KB
memoryfile.xml 427B
LAB2.X.production.hxl 8KB
LAB2.X.production.o 25KB
doprnt.d 105B
LAB2.X.production.cmf 33KB
LAB2.X.production.mum 383B
__eeprom.d 106B
doprnt.p1 8KB
LAB2.X.production.rlf 205KB
LAB2.X.production.hex 5KB
nbproject
Makefile-impl.mk 2KB
configurations.xml 14KB
Makefile-local-default.mk 2KB
private
private.xml 581B
configurations.xml 1KB
SuppressibleMessageMemo.properties 66B
Makefile-variables.mk 253B
project.xml 1KB
Makefile-default.mk 7KB
Makefile-genesis.properties 736B
debug
default
lcddemo.c 4KB
Makefile 3KB
build
default
production
main.p1 28KB
lcddemo.p1 28KB
lcddemo.i 48KB
main.p1.d 59B
lcddemo.p1.d 65B
main.i 48KB
共 39 条
- 1
DoubleQ666
- 粉丝: 21
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0