完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
mplab x ide 搭配xc8 ,给PIC16F1787芯片驱动12864LCD液晶屏显示一串数字结果只亮屏没有任何显示,求教各位是何原因? 是不是程序的问题 程序如下: #include // CONFIG1 #pragma config FOSC = XT // Oscillator Selection (XT Oscillator, Crystal/resonator connected between OSC1 and OSC2 pins) #pragma config WDTE = OFF // Watchdog Timer Enable (WDT enabled) #pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled) #pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is MCLR) #pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled) #pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled) #pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled) #pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin) #pragma config IESO = ON // Internal/External Switchover (Internal/External Switchover mode is enabled) #pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled) // CONFIG2 #pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off) #pragma config VCAPEN = OFF // Voltage Regulator Capacitor Enable bit (Vcap functionality is disabled on RA6.) #pragma config PLLEN = ON // PLL Enable (4x PLL enabled) #pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset) #pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.) #pragma config LPBOR = OFF // Low Power Brown-Out Reset Enable Bit (Low power brown-out is disabled) #pragma config LVP = ON #define rs RC0 //定义LCD的数据/命令控制口 #define rw RC1 //定义LCD的读/写控制口 #define e RC2 //定义LCD的使能口 #define p*** RB0 //定义通信方式控制口 #define rst RB1 //定义复位口 #define nop() asm("nop") // const unsigned char TAB1A[ ] = {0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39}; unsigned int lcd_x; //定义LCD页地址寄存器 unsigned int lcd_y; //定义LCD列地址寄存器 bit busy; //定义LCD忙标志位 void adc(); //ad端口初始化 void getad(); //ad转换 void keyscan(); //按键扫描 void init(); //单片机端口初始化 void lcd_init(); //lcd初始化 void send_d(unsigned char x); //申明送一字节数据函数 void send_i(unsigned char x); //申明送一字节控制命令函数 void chk_busy(); //申明检测LCD是否工作繁忙函数 void delayms(unsigned int n); //申明ms 延时函数 void delay(unsigned int m); //申明延时函数 void writelcd(const unsigned char *pt); //声明LCD写字符串函数 void main() { init(); //I/O初始化 while (1) { lcd_init(); //lcd初始化 delay(100); send_i(0x81); writelcd(TAB1A); //写字符串 delayms(100); } } void writelcd( const unsigned char *pt) //写字符串 { while(*pt) send_d(*pt++); } void init() //I/0口初始化 { TRISA = 0X00; ANSELA = 0X00; LATA = 0X10; TRISB = 0X00; ANSELB = 0X00; TRISD = 0X00; ANSELD = 0X00; } void lcd_init() //LCD初始化 { nop(); delay(40); p*** = 1; //选择并行通信 send_i(0x30); //8位接口,基本指令 delay(100); send_i(0x01); //清屏显示 delay(100); send_i(0x0C); //显示开,关光标,不闪烁 delay(100); send_i(0x06); // 光标从右向左加1位移动 } void send_d(unsigned char x) //发送一字节数据 { chk_busy(); rs = 1; rw = 0; delay(1); PORTD = x; e = 1; delay(1); e = 0; } void send_i(unsigned char x) //发送一字节指令 { chk_busy(); rs = 0; rw = 0; delay(1); PORTD = x; e = 1; delay(1); e = 0; } void chk_busy() //忙检测函数 { busy = 1; TRISD = 0XFF; rs = 0; rw = 1; while (busy) { nop();nop();nop(); e = 1; nop();nop();nop(); if (!RD7) busy = 0; nop();nop();nop(); e = 0; } e = 0; LATD = 0X00; } void delayms(unsigned int n) //延时函数 { unsigned int i,j; for (i = 0;i < n;i++) for (j=0;j<2000;j++); } void delay(unsigned int m ) //延时函数 { unsigned int i,j; for (i = 0;i < m;i++) for (j=0;j<10;j++); } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
求解外围电路实现的是4脚给持续低电平复位并正常工作,高电平不工作的原因
2084 浏览 1 评论
3629 浏览 3 评论
PIC1946程序有一个变量在运行过程中恢复初始值其他变量保持不变
2336 浏览 2 评论
2763 浏览 0 评论
PIC16F1825的RC5引脚,在主程序中操作无效,在中断中可以改变是为什么?
4027 浏览 5 评论
973浏览 0评论
用XC8编译PIC18F25K80时提示下面Error,求怎么解决这个问题
6360浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-4 00:03 , Processed in 0.760704 second(s), Total 75, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号