我正在制作pic单片机编程并最近向lcd制作了2个代码,一个在mplab中,另一个在mikroc中实际上都在isis中工作但是当我在实际中尝试它时只在微控制器中工作的mikroc代码我没有知道实际上是什么问题/为什么会发生这种情况我不认为这是硬件或软件代码,因为它是相同的电路,并且两个代码都在isis中工作如果有人想查看代码,所以这里是:
MIKROC:
// Lcd pinout settings
sbit LCD_RS at RC0_bit;
sbit LCD_EN at RC1_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D4 at RB4_bit;
// Pin direction
sbit LCD_RS_Direction at TRISC0_bit;
sbit LCD_EN_Direction at TRISC1_bit;
sbit LCD_D7_Direction at TRISB7_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB4_bit;
void main() {
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1, 3, "Hello!");
}
MPLAB:
main.c中:
#include "config.h"
unsigned char CurvyObject[8] = { 0x01,0x02,0x04,0x08,0x10,0x11,0x1f,0x00 };
void main(){
TRISB = 0;
TRISC = 0;
send_command(0x38);
__delay_us(40);
send_command(0x01);
__delay_ms(1.75);
send_command(0x0C);
__delay_us(40);
moveto(0, 0, 0, 0, 0, 0, 0);
__delay_us(40);
write_character(70);
__delay_us(50);
write_character(97);
__delay_us(50);
write_character(100);
__delay_us(50);
write_character(121);
__delay_us(50);
while(1);
}
的config.h:
/*
* File: config.h
* Author: Fady
*
* Created on August 14, 2014, 6:19 PM
*/
// PIC16F877A Configuration Bit Settings
// 'C' source line config statements
#include <xc.h>
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
// CONFIG
#pragma config FOSC = XT
#pragma config WDTE = OFF
#pragma config PWRTE = OFF
#pragma config BOREN = ON
#pragma config LVP = ON
#pragma config CPD = OFF
#pragma config WRT = OFF
#pragma config CP = OFF
#define _XTAL_FREQ 4000000
unsigned char i;
//Library Declaration:
void send_command(int command);
void write_character(int character);
void enable_blink();
void moveto(char b6, char b5, char b4, char b3, char b2, char b1, char b0);
void send_command(int command){
PORTB = command;
PORTCbits.RC0 = 0;
enable_blink();
}
void write_character(int character){
PORTB = character;
PORTCbits.RC0 = 1;
enable_blink();
}
void enable_blink(){
PORTCbits.RC1 = 1;
__delay_ms(10);
PORTCbits.RC1 = 0;
__delay_ms(10);
}
void moveto(char b6, char b5, char b4, char b3, char b2, char b1, char b0){
PORTCbits.RC0 = 0;
PORTBbits.RB7 = 1;
PORTBbits.RB6 = b6;
PORTBbits.RB5 = b5;
PORTBbits.RB4 = b4;
PORTBbits.RB3 = b3;
PORTBbits.RB2 = b2;
PORTBbits.RB1 = b1;
PORTBbits.RB0 = b0;
enable_blink();
}
答案 0 :(得分:0)
最好在启动程序之前确保所有外围设备和输出都处于已知状态。 如评论中所述,您从未确定LCD是否正确配置了R / W引脚。
PORTCbits.RC2=0; // The Microcontroller will always write to the LCD
// Replace RC2 with your R/W pin
除此之外,我将您的LCD库与您制作的LCD库进行了比较,但未配置输入模式,请尝试添加:
send_command(6); //Cursor Move direction and Display Shift
查看此通用数据表,了解您是否根据需要配置了模块:http://www.lcd-module.com/eng/pdf/doma/dip162-de.pdf
另一方面,我看到了moveto();函数用于定位光标,我可以建议我的方法:
// L1=128,L2=192,L3=144,L4=208
send_command(L1+6); // Go to the 6th character of the first line