完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我试着用PIC16F86/PIC18F24K40集成电路接口HTTP//www. XMuCARAR.COM/AXPLAD/CMPDF/GDM1601A010107951 18.PDF.我想用8位模式来编码LCD。我在寻找示例代码,在那里我可以编写简单的“Hello World”。
以上来自于百度翻译 以下为原文 I am trying to Interface http://www.xmocular.com/Upload/CMpdf/GDM1601A-01010795118.pdf with PIC16F886/PIC18F24k40 IC. I would like to code LCD in 8 bit mode. I am looking for example code Where i can write simple "Hello World " Attachment(s) 1.txt (3.14 KB) - downloaded 75 times |
|
相关推荐
19个回答
|
|
它是1x16液晶显示器吗?如果是这样,你可以在这里得到一个参考:HTTP://www. EncWebs.COM/ARM7/LCD-16X2接口-LPC2148—8位模式,给出的例子是2x16,但是有了这个RF,你就可以走了。
以上来自于百度翻译 以下为原文 Is it a 1x16 LCD? If so, you can get a reference here: http://www.electronicwings.com/arm7/lcd-16x2-interfacing-with-lpc2148-8-bit-modeThe example given is for 2x16 but with this ref you are good to go. |
|
|
|
7-定义为LED的RC6//Pin定义了CLK RC2α定义DeDATA RC0//QH引脚9 7HC165α定义SLD LC1//SLD Pin 1 7HC165α定义CLKYIN RC3//PIN 15 7HC165α定义D1 RB0*定义D1 RB1α定义D2 RB2α定义D4 RB4α定义D5 RB5α定义D6 RB6α定义D7 RB7α定义LeD1 RC定义RS RA2*定义EN RA1unChar char rw=0;/i已将此引脚连接到GndValLCDyCMDRead(char CMD){DATABUS=CMD;/ /将命令发送到LCD RS=0;/ /通过拉RS低RW=0来选择命令寄存器;/ /通过拉RW低EN=1来选择写入操作;/ /在E发送高Low Pusle= 0;γ-DelaySmith(1);} LCDA*CMDRead(0x00);/ /清除LCD LCDY-CMDRead(0x01);//将游标移动到第一位置} LCDLeSHIVTTHORY(){LCDY-CMDRead(0x01);LCDA*CMDRead(0x0C);} LCDLeSHIFT THELFET(){LCDY-CMDRead(0x01);LCDA*CMDRead(0x08);} LCDLyDATAWORD(空隙LCDA数据写入)Nel-Pin Sy-DelayuUS(10);EN(Car DAT){DATABUS=DAT;/ /将数据发送到LCD RS=1;/ /通过拉RS高RW=0选择数据寄存器;/ /通过拉RW低EN=1来选择写入操作;/ /在启用PINα-DelayuUS(10)发送Low Pusle高;EN=0;GCD-PTDR(*STRIGIN PTR++);} LCDLGIN():LCDA*CMDRead(0x30);/配置8位模式的LCD,2行和5x7字体LCDY-CMDRead(0x0C);//显示和光标关闭LCDY-CMDRead(0x01);/ /清除显示屏幕LCDY-CMDRead(0x06);/ /增量光标LCDY-CMDRead(0x80);/ /设置光标P与第一行、第一列}空主(空){//初始化设备SyrSePrimalIZE()相匹配;//如果在PIC18高/低优先级模式下使用中断,则需要启用全局高和低中断/ /如果在PIC中程兼容模式中使用中断,则需要启用全局和/或I/O中断/ /使用以下宏:/ /启用高优先级全局中断//ClothTraceGlobal SwitthEngEnable();/ /启用低优先级全局中断。//CuffTracGlobal StudioLabEnable();/ /禁用高优先级全局中断//CuttTraceGlobal中断thabable();/禁用低优先级全局中断。//CuffTracGlobal StuttLoDeabable(;)/ /启用全局中断/中断/全局中断();/ /启用外围中断/ /中断/外围设备中断();/ /禁用全局中断/中断/全局中断中断();/ /禁用外围中断/ /中断同时,(1){//SHIVTIGRealStEnter();//Read SypIngs165();LCDyDISPACTISH(“欢迎”);γ-DelayyMs(1000);//SHIFTUnATAOFAuthRebug();//工作精细需要读取数据LCDXDATAWORD(“H”);}我的代码看起来像上面
以上来自于百度翻译 以下为原文 #define LED1 RC7 #define LED RC6 // Pin assigned for LED #define CLK RC2 #define DISPDATA RC0 // QH PIN 9 74hc165 #define SH_LD RC1 // SHLD PIN1 74HC165 #define CLK_INH RC3 // PIN 15 74hc165 #define D0 RB0 #define D1 RB1 #define D2 RB2 #define D3 RB3 #define D4 RB4 #define D5 RB5 #define D6 RB6 #define D7 RB7 #define rs RA2 #define en RA1 unsigned char rw=0;// I have connected this pin to gnd void LCD_CmdWrite( char cmd) { databus=cmd; // Send the command to LCD rs=0; // Select the Command Register by pulling RS LOW rw=0; // Select the Write Operation by pulling RW LOW en=1; // Send a High-to-Low Pusle at Enable Pin __delay_us(10); en=0; __delay_ms(1); } Lcd_Clear() { LCD_CmdWrite(0x00); //Clear the LCD LCD_CmdWrite(0x01); //Move the curser to first position } void Lcd_Shift_Right() { LCD_CmdWrite(0x01); LCD_CmdWrite(0x0C); } void Lcd_Shift_Left() { LCD_CmdWrite(0x01); LCD_CmdWrite(0x08); } void LCD_DataWrite( char dat) { databus=dat; // Send the data to LCD rs=1; // Select the Data Register by pulling RS HIGH rw=0; // Select the Write Operation by pulling RW LOW en=1; // Send a High-to-Low Pusle at Enable Pin __delay_us(10); en=0; __delay_ms(1); } void LCD_DisplayString(char *string_ptr) { while(*string_ptr) LCD_DataWrite(*string_ptr++); } void lcd_init() { LCD_CmdWrite(0x30); // Configure the LCD in 8-bit mode, 2 line and 5x7 font LCD_CmdWrite(0x0C); // Display On and Cursor Off LCD_CmdWrite(0x01); // Clear display screen LCD_CmdWrite(0x06); // Increment cursor LCD_CmdWrite(0x80); // Set cursor position to 1st line, 1st column } void main(void) { // Initialize the device SYSTEM_Initialize(); // If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts // If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global and Peripheral Interrupts // Use the following macros to: // Enable high priority global interrupts //INTERRUPT_GlobalInterruptHighEnable(); // Enable low priority global interrupts. //INTERRUPT_GlobalInterruptLowEnable(); // Disable high priority global interrupts //INTERRUPT_GlobalInterruptHighDisable(); // Disable low priority global interrupts. //INTERRUPT_GlobalInterruptLowDisable(); // Enable the Global Interrupts //INTERRUPT_GlobalInterruptEnable(); // Enable the Peripheral Interrupts //INTERRUPT_PeripheralInterruptEnable(); // Disable the Global Interrupts //INTERRUPT_GlobalInterruptDisable(); // Disable the Peripheral Interrupts //INTERRUPT_PeripheralInterruptDisable(); lcd_init(); while (1) { //Shift_Register(); //read_inputs_165(); LCD_DisplayString("welcome"); __delay_ms(1000); //shiftIndataFromRegister();//working fine need to read data LCD_DataWrite("h"); } } My code look like above |
|
|
|
我最初用ARDINO编写了C代码。是的,它的1x16行液晶显示器。在ARDUINO中,我们将得到初始化和函数直接向前的库。我正在测试基础设施,它不会像预期的那样工作。
以上来自于百度翻译 以下为原文 I have written c code using Arduino Initially. Yes its 1X16 row LCD display. In arduino we will get library where initialization and functions are straight forward. I am testing basic intilization it wont working as expected. |
|
|
|
在LCDGIN()函数中需要更长的延迟。类似:
以上来自于百度翻译 以下为原文 You need longer delays in the LCD_Init() function. Something like: void LCD_Init_Display(void) { LCD_RW = 0; //Set for write Delay_mSec(20); LCD_Write_Command( 0b00110000); //Function set 8 bit Delay_mSec(6); //Need at least 4.1 mSec LCD_Write_Command( 0b00110000 ); //Function set 8 bit Delay_uSec(150); //Need at least 100 uSec LCD_Write_Command( 0b00110000 ); //Function set 8 bit Delay_uSec(50); //0 0 1 DL N F x x ;DL: 1=8Bit 0=4Bit, N: 1=2Line 0=1Line, F: 1=10Dot 0=8Dot LCD_Write_Command( 0b00111000 ); //8 bit Function set 2 lines, 5x8 dots Delay_uSec(50); LCD_Write_Command( 0b00001000 ); //Display off Delay_uSec(50); LCD_Write_Command( LCD_CLEAR ); //Display clear Delay_uSec(50); LCD_Write_Command( 0b00000110 ); //Entry mode set, <2> 1=incr, <1> 1=shift Delay_uSec(50); LCD_Write_Command( LCD_HOME ); //Cursor home Delay_uSec(50); // Cursor is underline, Blink flashes character ;Display ON/OFF, Cursor, Blink LCD_Write_Command( LCD_ON_OFF | LCD_ON ); //| LCD_CUR_ON | LCD_CUR_BLINK ); Delay_mSec(20); //long delay } |
|
|
|
我已经修改了代码,但我没有发现任何变化。如果你看到我的第一个线程,我没有初始化DATAARGISSTER位D0—D7在ARDUION中初始化。EWORE如何配置8位DATALLYNEMY布线?CTD的所有数据线到PORTB和RS和EN连接到RA1和RA2。我用PIC18F24K40进行编码。像链接中显示的聪明一样,有图书馆功能吗?
以上来自于百度翻译 以下为原文 i HAVE MODIFIED CODE AS BELOW BUT I DIDNT FIND ANY CHANGES. If u see my first thread i have not intialise the dataregister bit D0-D7 like intialize in arduino const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; LiquidCrystal lcd(rs, en, d4, d5, d6, d7); void LCD_Init_Display(void) { LCD_CmdWrite( 0b00110000); //Function set 8 bit __delay_ms(6); //Need at least 4.1 mSec LCD_CmdWrite( 0b00110000 ); //Function set 8 bit __delay_us(150); //Need at least 100 uSec LCD_CmdWrite( 0b00110000 ); //Function set 8 bit __delay_us(50); //0 0 1 DL N F x x ;DL: 1=8Bit 0=4Bit, N: 1=2Line 0=1Line, F: 1=10Dot 0=8Dot LCD_CmdWrite( 0b00111000 ); //8 bit Function set 2 lines, 5x8 dots __delay_us(50); LCD_CmdWrite( 0b00001000 ); //Display off __delay_us(50); LCD_CmdWrite(0X01); //Display clear __delay_us(50); LCD_CmdWrite( 0b00000110 ); //Entry mode set, <2> 1=incr, <1> 1=shift __delay_us(50); //LCD_CmdWrite( LCD_HOME ); //Cursor home __delay_us(50); // Cursor is underline, Blink flashes character ;Display ON/OFF, Cursor, Blink LCD_CmdWrite( 0X0F ); //| LCD_CUR_ON | LCD_CUR_BLINK ); __delay_ms(20); //long delay } i.e how can i config for 8 bit dataline void Lcd_SetBit(char data_bit) //Based on the Hex value Set the Bits of the Data Lines { if(data_bit& 1) D4 = 1; else D4 = 0; if(data_bit& 2) D5 = 1; else D5 = 0; if(data_bit& 4) D6 = 1; else D6 = 0; if(data_bit& 8) D7 = 1; else D7 = 0; } my wiring as below https://electrosome.com/interfacing-lcd-with-pic-microcontroller-hi-tech-c/ i have connected all data line to PORTB and RS and EN connected to RA1 & RA2. I am using PIC18F24k40 for coding. Like wise shown in link is there any library function avilable? |
|
|
|
你为什么不使用他们的图书馆?LCD与PIC单片机的接口——高技术,那里有很多LIBS。这是我的。
以上来自于百度翻译 以下为原文 Why don't you use their library? Interfacing LCD with PIC Microcontroller – Hi Tech C There lots of libs available out there. Here is mine. |
|
|
|
HI,为HiTeC C编写的库代码,可能与XC8编译器一起工作。它是同一个编译器,它在Microchip收购HiTeX编译器公司之后被重新命名。与所有连接到PORTB的8个数据位的LCD连接可能很难调试,因为PIN RB6和RB7是编程/DEB所需要的。VoLKI代码可用于4位模式或8位模式,具有预处理器定义。迈西尔
以上来自于百度翻译 以下为原文 Hi, Library code written for HiTech C, will probably work with XC8 compiler. It is the same compiler, it was renamed after Microchip bought HiTech compiler company. LCD connection with all 8 data bits connected to PORTB, may be difficult to debug, since pins RB6 and RB7 are needed for programming / debugging signals. The code by vloki may be used for 4 bit mode or 8 bit mode with a preprocessor definition. Mysil |
|
|
|
@ VoKi我试用你的库共享并给你更新。@ MysIL是的。测试我可以使用其他的端口。我不需要使用基于I2C的LCD。在4位模式和8位模式之间有什么区别。我发现只有数据线是模式差中使用的差异和命令。当我们使用4位模式?如果我使用16X2 LCD天气,它限制了我使用显示器。或者我可以使用显示,只要我的代码大小增加,然后发送4位第一位,然后另外4位作为下一条指令。
以上来自于百度翻译 以下为原文 @volki i tryout your library share and give u update. @ mysil yes it true for testing i can use other port Else i need t use I2c based LCD .what make difference between 4 bit mode and 8 bit mode.i found only data line are difference and command used in mode difference. when we are using 4 bit mode?? if i am using 16X2 LCd weather it restrict me for using display. or i can complete use the display provided my code size increase and send 4 bit first & then other 4 bit as next instruction |
|
|
|
如果我们只剩下4行,或者不想花8行数据?
以上来自于百度翻译 以下为原文 If we have only 4 lines left or don't want to spend 8 lines for data? |
|
|
|
使用4位模式,一个8位端口可以用于所有需要的接口。这里是处理LCD的4/8位写入的一种方式:
以上来自于百度翻译 以下为原文 With 4 bit mode, a single 8 bit port can be used for all required interfacing. Here is one way to handle 4/8 bit writes to the LCD: union LCDv8bit { char all; struct { unsigned LN : 4; unsigned HN : 4; }; struct { unsigned bit0 : 1; unsigned bit1 : 1; unsigned bit2 : 1; unsigned bit3 : 1; unsigned bit4 : 1; unsigned bit5 : 1; unsigned bit6 : 1; unsigned bit7 : 1; }; }; union LCDv8bit LCD_data; // bitfield variable (bitwise acess) void Lcd_Write(char BYTE) { LCD_data.all = BYTE; NOP; LCD_D7 = LCD_data.bit7; NOP; LCD_D6 = LCD_data.bit6; NOP; LCD_D5 = LCD_data.bit5; NOP; LCD_D4 = LCD_data.bit4; #ifndef LCD_USE_8BIT_DATA LCD_STROBE(); NOP; LCD_D7 = LCD_data.bit3; NOP; LCD_D6 = LCD_data.bit2; NOP; LCD_D5 = LCD_data.bit1; NOP; LCD_D4 = LCD_data.bit0; #else NOP; LCD_D3 = LCD_data.bit3; NOP; LCD_D2 = LCD_data.bit2; NOP; LCD_D1 = LCD_data.bit1; NOP; LCD_D0 = LCD_data.bit0; #endif LCD_STROBE(); __delay_us(50); } |
|
|
|
|
|
|
|
是的,我想你前一段时间提供了一个LCDLILBHOL.C项目。我从代码的各种例子中提取了一些碎片,并根据需要修改它们。似乎很多人都在努力让LCD显示器正常工作。我发现了各种各样的C和汇编的代码,对于不同的设备,主要是PICS和ARDUINO,我也尝试着为MikRO-C编写代码。它们的库是预先编译的,没有源代码,编译器有一些难以复制的特殊指令。谢谢。
以上来自于百度翻译 以下为原文 Yes, I think you provided an LCD_lib_busy.c project some time ago. I've taken bits and pieces from various examples of code and modified them as needed. It seems that a lot of people have struggled with getting LCD displays to work properly. I have found code in various flavors of C and assembly for different devices, mostly PICs and Arduino, and I was also trying to port code written for Mikro-C. Their libraries are pre-compiled without source and their compiler has some special instructions that were hard to duplicate. Thanks. |
|
|
|
我的问题仍在抗拒。按照我的建议,我修改了下面的代码。在LCD显示器上我看不到任何东西,当我打开电源时,会显示黑点。我试图调整合同的工作,但没有迹象显示字符16x2 LCD天气引脚15和引脚16应该连接或不?我一直闲置着做作业。我已经从16x1替换为16x2,因为所有工作在16x2 以上来自于百度翻译 以下为原文 My problem still resist. As per suggestion i modified code as below. I couldnot able to see anything on LCD display, When i power ON Segment will show black dots. I tried to adjust contract its working but no sign of display character In 16X2 LCD weather pin 15& pin 16 should be connected or not? I have kept idle for current operation . I have replace from 16X1 to 16X2 because all working on 16X2 /** Generated Main Source File Company: Microchip Technology Inc. File Name: main.c Summary: This is the main file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs Description: This header file provides implementations for driver APIs for all modules selected in the GUI. Generation Information : Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.45 Device : PIC18F24K40 Driver Version : 2.00 The generated drivers are tested against the following: Compiler : XC8 1.35 MPLAB : MPLAB X 3.40 */ /* (c) 2016 Microchip Technology Inc. and its subsidiaries. You may use this software and any derivatives exclusively with Microchip products. THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE TERMS. */ #include "mcc_generated_files/mcc.h" //#define LED1 RC7 #define D0 RC0 #define D1 RC1 #define D2 RC2 #define D3 RC3 #define D4 RC4 #define D5 RC5 #define D6 RC6 #define D7 RC7 #define RS RA2 #define RW RA3 #define EN RA1 void PIN_MANAGER_Initialize(void) { /** LATx registers */ LATA = 0x00; LATB = 0x00; LATC = 0x00; /** TRISx registers */ TRISA = 0x00; TRISB = 0x00; TRISC = 0x00; /** ANSELx registers */ ANSELC = 0x00; ANSELB = 0x00; ANSELA = 0x00; /** WPUx registers */ WPUE = 0x00; WPUB = 0x00; WPUA = 0x00; WPUC = 0x00; /** ODx registers */ ODCONA = 0x00; ODCONB = 0x00; ODCONC = 0x00; } void Lcd8_Port(char a) { if(a & 1) D0 = 1; else D0 = 0; if(a & 2) D1 = 1; else D1 = 0; if(a & 4) D2 = 1; else D2 = 0; if(a & 8) D3 = 1; else D3 = 0; if(a & 16) D4 = 1; else D4 = 0; if(a & 32) D5 = 1; else D5 = 0; if(a & 64) D6 = 1; else D6 = 0; if(a & 128) D7 = 1; else D7 = 0; } void Lcd8_Cmd(char a) { RS = 0; // => RS = 0 Lcd8_Port(a); //Data transfer EN = 1; // => E = 1 __delay_ms(5); EN = 0; // => E = 0 } void Lcd8_Clear() { Lcd8_Cmd(0X01); } void Lcd8_Set_Cursor(char a, char b) { if(a == 1) Lcd8_Cmd(0x80 + b); else if(a == 2) Lcd8_Cmd(0xC0 + b); } void Lcd8_Init() { Lcd8_Port(0x00); RS = 0; __delay_ms(25); ///////////// Reset process from datasheet ///////// Lcd8_Cmd(0x30); __delay_ms(5); Lcd8_Cmd(0x30); __delay_ms(15); Lcd8_Cmd(0x30); ///////////////////////////////////////////////////// Lcd8_Cmd(0x38); //function set Lcd8_Cmd(0x0C); //display on,cursor off,blink off Lcd8_Cmd(0x01); //clear display Lcd8_Cmd(0x06); //entry mode, set increment } void Lcd8_Write_Char(char a) { RS = 1; // => RS = 1 Lcd8_Port(a); //Data transfer EN = 1; // => E = 1 __delay_ms(4); EN = 0; // => E = 04 } void Lcd8_Write_String(char *a) { int i; for(i=0;a!=' |