首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >MPLAB代码不工作

MPLAB代码不工作
EN

Stack Overflow用户
提问于 2014-08-19 21:19:39
回答 1查看 995关注 0票数 0

我正在做pic微控制器编程,最近去lcd做了两个代码,一个在mplab中,另一个在mikroc中实际上都可以在isis中工作,但当我在实际中尝试时,只有mikroc代码在微控制器中工作,我不知道实际上是什么问题/为什么会发生这种情况我不猜这是一个硬件或软件代码,因为它是相同的电路,两个代码都在isis中工作,所以如果有人想查看代码,请看这里:

mikroC:

代码语言:javascript
运行
复制
    // 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:

代码语言:javascript
运行
复制
       #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:

代码语言:javascript
运行
复制
/* 
             * 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();

            }
EN

回答 1

Stack Overflow用户

发布于 2015-08-21 14:14:19

在启动程序之前,最好确保所有外围设备和输出都处于已知状态。如注释中所述,您从未确保LCD的读/写引脚配置正确。

代码语言:javascript
运行
复制
PORTCbits.RC2=0; // The Microcontroller will always write to the LCD   
                 // Replace RC2 with your R/W pin

除了我将您的LCD库与我创建的LCD库进行了比较,并且您没有配置进入模式之外,尝试添加以下内容:

代码语言:javascript
运行
复制
send_command(6);      //Cursor Move direction and Display Shift

查看此通用数据表,查看是否按所需配置了该模块:http://www.lcd-module.com/eng/pdf/doma/dip162-de.pdf

顺便说一句,我看到moveto();函数是用来定位光标的,我可以建议我的方法:

代码语言:javascript
运行
复制
// L1=128,L2=192,L3=144,L4=208 
send_command(L1+6);    // Go to the 6th character of the first line
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25384499

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档