我正在研究 pic 微控制器编程,最近去了 lcd 制作了 2 个代码,一个在 mplab 中,另一个在 mikroc 中实际上都在 isis 中工作,但是当我真正尝试它时,只有 mikroc 代码在微控制器中工作我不知道实际上是什么是问题/为什么会发生这种情况我不认为这是硬件或软件代码,因为它是相同的电路并且两个代码都在 isis 中工作所以如果有人想查看代码,那么这里是:
微克:
// 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!");
}
实验室:
主.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);
}
配置.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();
}