Перейти к содержанию

Lcd Библиотека Под C18 Компилятор Mplabx


vv7

Рекомендуемые сообщения

Всем привет !

Столкнулся с проблемой написания кода управления LCD экранчиком под C18 компилятором. В XC8 компиляторе или в MicroC IDE есть те или иные библиотеки для работы с LCD экраном.

От отчаяния переписываю код из XC8 под C18, но пока ничего не выходит. В виду ускорения процесса ... прошу помощи. Может кто поделиться ?

Всем откликнувшимся, отдельное спасибо !!! :big_boss:

Хотя, вот нашёл что-то http://www.romux.com/bootloader/usb-pic18f4550/lcd-hello-world

Ссылка на комментарий
Поделиться на другие сайты

Реклама: ООО ТД Промэлектроника, ИНН: 6659197470, Тел: 8 (800) 1000-321

20% скидка на весь каталог электронных компонентов в ТМ Электроникс!

Акция "Лето ближе - цены ниже", успей сделать выгодные покупки!

Плюс весь апрель действует скидка 10% по промокоду APREL24 + 15% кэшбэк и бесплатная доставка!

Перейти на страницу акции

Реклама: ООО ТМ ЭЛЕКТРОНИКС, ИНН: 7806548420, info@tmelectronics.ru, +7(812)4094849

Вот такой экранчик ( В атаче ). Замучался уже его запускать. Дело в том, что даже в Proteus не работает с программой из под MicroC, а вот из C18 - ноль. Единственное - 20 ошибок ( В атаче ). Чтож может быть ?

Код, который не работает на экранчике ничего не высвечивается. Ни в Proteus, ни в жизни. ( Таймер просто работает, но не на что не реагирует и не влияет ):

#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <timers.h>
#include <delays.h>
#include "lcdtest.h"

static int ms = 0;
static int o = 0;
void high_isr (void);

#pragma code high_vector = 0x08
void interrupt_at_high_vector(void) {
_asm GOTO high_isr _endasm
}

void DelayFor18TCY( void)
{
Delay10TCYx(1);
Delay1TCY();
Delay1TCY();
Delay1TCY();
Delay1TCY();
Delay1TCY();
Delay1TCY();
Delay1TCY();
Delay1TCY();
}
void DelayPORXLCD (void)
{
Delay1KTCYx(75);
return;
}
void DelayXLCD (void)
{
Delay1KTCYx(25);
return;
}
#pragma interrupt high_isr
void high_isr (void) {
if (INTCONbits.TMR0IF){
 INTCONbits.TMR0IF = 0;				
 TMR0H = 0xF6;
 TMR0L = 0x3C;
 ms++;
}
}
void main (void) {

// TRISA = 0x00;
// PORTA = 0x00;
TRISB = 0xF0;
PORTB = 0x00;
// TRISC = 0x00;
// PORTC = 0x00;
// TRISD = 0x00;
// PORTD = 0x00;
// TRISE = 0x00;
// PORTE = 0x00;

ADCON1 = 0x0F;
T0CON = 0b10001000; // 10000101 TMR0ON T0PS2 T0PS0
TMR0H = 0xF6;
TMR0L = 0x3C;
INTCON = 0x20;			
INTCON2 = 0x04;
RCONbits.IPEN = 1;				
INTCONbits.GIEH = 1;

OpenXLCD();
putrsXLCD("Hello world !");

while (1) {
 if ( ms == 1000 ) {
 if ( o == 0 ) { PORTB = 0x0E; o = 1; } else
 if ( o == 1 ) { PORTB = 0x0D; o = 2; } else
 if ( o == 2 ) { PORTB = 0x0B; o = 3; } else
 if ( o == 3 ) { PORTB = 0x07; o = 4; } else
 if ( o == 4 ) { PORTB = 0x0B; o = 5; } else
 if ( o == 5 ) { PORTB = 0x0D; o = 0; }
 ms = 0;
 }
}
}

Файл "config.h":

// PIC18F452 Configuration Bit Settings
// 'C' source line config statements
#include <p18f452.h>
// CONFIG1H
#pragma config OSC = HS		 // Oscillator Selection bits (HS oscillator)
#pragma config OSCS = OFF	 // Oscillator System Clock Switch Enable bit (Oscillator system clock switch option is disabled (main oscillator is source))
// CONFIG2L
#pragma config PWRT = OFF	 // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOR = ON		 // Brown-out Reset Enable bit (Brown-out Reset enabled)
#pragma config BORV = 20	 // Brown-out Reset Voltage bits (VBOR set to 2.0V)
// CONFIG2H
#pragma config WDT = OFF	 // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
#pragma config WDTPS = 128	 // Watchdog Timer Postscale Select bits (1:128)
// CONFIG3H
#pragma config CCP2MUX = ON	 // CCP2 Mux bit (CCP2 input/output is multiplexed with RC1)
// CONFIG4L
#pragma config STVR = ON	 // Stack Full/Underflow Reset Enable bit (Stack Full/Underflow will cause RESET)
#pragma config LVP = OFF	 // Low Voltage ICSP Enable bit (Low Voltage ICSP disabled)
// CONFIG5L
#pragma config CP0 = OFF	 // Code Protection bit (Block 0 (000200-001FFFh) not code protected)
#pragma config CP1 = OFF	 // Code Protection bit (Block 1 (002000-003FFFh) not code protected)
#pragma config CP2 = OFF	 // Code Protection bit (Block 2 (004000-005FFFh) not code protected)
#pragma config CP3 = OFF	 // Code Protection bit (Block 3 (006000-007FFFh) not code protected)
// CONFIG5H
#pragma config CPB = OFF	 // Boot Block Code Protection bit (Boot Block (000000-0001FFh) not code protected)
#pragma config CPD = OFF	 // Data EEPROM Code Protection bit (Data EEPROM not code protected)
// CONFIG6L
#pragma config WRT0 = OFF	 // Write Protection bit (Block 0 (000200-001FFFh) not write protected)
#pragma config WRT1 = OFF	 // Write Protection bit (Block 1 (002000-003FFFh) not write protected)
#pragma config WRT2 = OFF	 // Write Protection bit (Block 2 (004000-005FFFh) not write protected)
#pragma config WRT3 = OFF	 // Write Protection bit (Block 3 (006000-007FFFh) not write protected)
// CONFIG6H
#pragma config WRTC = OFF	 // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write protected)
#pragma config WRTB = OFF	 // Boot Block Write Protection bit (Boot Block (000000-0001FFh) not write protected)
#pragma config WRTD = OFF	 // Data EEPROM Write Protection bit (Data EEPROM not write protected)
// CONFIG7L
#pragma config EBTR0 = OFF	 // Table Read Protection bit (Block 0 (000200-001FFFh) not protected from Table Reads executed in other blocks)
#pragma config EBTR1 = OFF	 // Table Read Protection bit (Block 1 (002000-003FFFh) not protected from Table Reads executed in other blocks)
#pragma config EBTR2 = OFF	 // Table Read Protection bit (Block 2 (004000-005FFFh) not protected from Table Reads executed in other blocks)
#pragma config EBTR3 = OFF	 // Table Read Protection bit (Block 3 (006000-007FFFh) not protected from Table Reads executed in other blocks)
// CONFIG7H
#pragma config EBTRB = OFF	 // Boot Block Table Read Protection bit (Boot Block (000000-0001FFh) not protected from Table Reads executed in other blocks)
#pragma target clock 10_000_000

/*source : www.romux.com */
#ifndef __bootlcd_H
#define __bootlcd_H
#include "p18cxxx.h"
/* PIC18 BOOTLCD peripheral routines.
*
* Notes:
*	 - These libraries routines are written to support the
*	 Hitachi HD44780 LCD controller.
*	 - The user must define the following items:
*		 - The LCD interface type (4- or 8-bits)
*		 - If 4-bit mode
*			 - whether using the upper or lower nibble
*		 - The data port
*			 - The tris register for data port
*			 - The control signal ports and pins
*			 - The control signal port tris and pins
*		 - The user must provide three delay routines:
*			 - DelayFor18TCY() provides a 18 Tcy delay
*			 - DelayPORXLCD() provides at least 15ms delay
*			 - DelayXLCD() provides at least 5ms delay
*/
/* Interface type 8-bit or 4-bit
* For 8-bit operation uncomment the #define BIT8
*/
/* #define BIT8 */
/* When in 4-bit interface define if the data is in the upper
* or lower nibble. For lower nibble, comment the #define UPPER
*/
#define UPPER 1
/* DATA_PORT defines the port to which the LCD data lines are connected */
#define DATA_PORT	 PORTD
#define TRIS_DATA_PORT TRISD
/* CTRL_PORT defines the port where the control lines are connected.
* These are just samples, change to match your application.
*/
#define RW_PIN LATCbits.LATC1	 /* PORT for RW */
#define TRIS_RW TRISCbits.TRISC1	 /* TRIS for RW */
#define RS_PIN LATCbits.LATC0	 /* PORT for RS */
#define TRIS_RS TRISCbits.TRISC0	 /* TRIS for RS */
#define E_PIN LATCbits.LATC2 /* PORT for D */
#define TRIS_E TRISCbits.TRISC2	 /* TRIS for E */
/* Display ON/OFF Control defines */
#define DON		 0b00001111 /* Display on	 */
#define DOFF	 0b00001011 /* Display off	 */
#define CURSOR_ON 0b00001111 /* Cursor on	 */
#define CURSOR_OFF 0b00001101 /* Cursor off	 */
#define BLINK_ON 0b00001111 /* Cursor Blink */
#define BLINK_OFF 0b00001110 /* Cursor No Blink */
/* Cursor or Display Shift defines */
#define SHIFT_CUR_LEFT 0b00000100 /* Cursor shifts to the left */
#define SHIFT_CUR_RIGHT 0b00000101 /* Cursor shifts to the right */
#define SHIFT_DISP_LEFT 0b00000110 /* Display shifts to the left */
#define SHIFT_DISP_RIGHT 0b00000111 /* Display shifts to the right */
/* Function Set defines */
#define FOUR_BIT 0b00101100 /* 4-bit Interface			 */
#define EIGHT_BIT 0b00111100 /* 8-bit Interface			 */
#define LINE_5X7 0b00110000 /* 5x7 characters, single line */
#define LINE_5X10 0b00110100 /* 5x10 characters			 */
#define LINES_5X7 0b00111000 /* 5x7 characters, multiple line */
void OpenXLCD(void);
void SetCGRamAddr(PARAM_SCLASS unsigned char);
void SetDDRamAddr(PARAM_SCLASS unsigned char);
unsigned char BusyXLCD(void);
unsigned char ReadAddrXLCD(void);
char ReadDataXLCD(void);
void WriteCmdXLCD(PARAM_SCLASS unsigned char);
void WriteCmd8bit(PARAM_SCLASS unsigned char);
void WriteDataXLCD(PARAM_SCLASS char);
#define putcXLCD WriteDataXLCD
void putsXLCD(PARAM_SCLASS char *);
void putrsXLCD(const rom char *);
extern void DelayFor18TCY(void);
extern void DelayPORXLCD(void);
extern void DelayXLCD(void);

/* OpenXLCD
* Configures I/O pins for external LCD
*/
/********************************************************************
*	 Function Name: OpenXLCD								 *
*	 Return Value: void									 *
*	 Description: This routine configures the LCD. Based on *
*					 the Hitachi HD44780 LCD controller. The	 *
*					 routine will configure the I/O pins of the *
*					 microcontroller, setup the LCD for 4- or *
*					 8-bit mode and clear the display. The user *
*					 must provide three delay routines:		 *
*					 DelayFor18TCY() provides a 18 Tcy delay	 *
*					 DelayPORXLCD() provides at least 15ms delay *
*					 DelayXLCD() provides at least 5ms delay	 *
********************************************************************/
void OpenXLCD()
{
 // The data bits must be either a 8-bit port or the upper or
 // lower 4-bits of a port. These pins are made into inputs
					 // Upper 4-bits of the port
 DATA_PORT &= 0x0f;
 TRIS_DATA_PORT &= 0x0F;
 TRIS_RW = 0;				 // All control signals made outputs
 TRIS_RS = 0;
 TRIS_E = 0;
 RW_PIN = 0;					 // R/W pin made low
 RS_PIN = 0;					 // Register select pin made low
 E_PIN = 0;					 // Clock pin made low
 // Delay for 15ms to allow for LCD Power on reset
	 Delay1KTCYx(75); // Delay of 15ms
//-------------------reset procedure through software----------------------	
WriteCmdXLCD(0x30);
Delay10KTCYx(0x05);
WriteCmdXLCD(0x30);
Delay10KTCYx(0x01);

WriteCmdXLCD(0x32);
while( BusyXLCD() );
//------------------------------------------------------------------------------------------

 // Set data interface width, # lines, font
 while(BusyXLCD());			 // Wait if LCD busy
 WriteCmd8bit(FOUR_BIT & LINES_5X7);		 // Function set cmd
while(BusyXLCD());
//WriteCmdXLCD(LINES_5X7);
 // Turn the display on then off
 Delay10KTCYx(0x05);			 // Wait if LCD busy
 WriteCmdXLCD(DOFF&CURSOR_OFF&BLINK_OFF);	 // Display OFF/Blink OFF
 while(BusyXLCD());			 // Wait if LCD busy
 WriteCmdXLCD(DON&CURSOR_OFF&BLINK_OFF);		 // Display ON/Blink ON
 // Clear display
 while(BusyXLCD());			 // Wait if LCD busy
 WriteCmdXLCD(0x01);			 // Clear display
 // Set entry mode inc, no shift
 while(BusyXLCD());			 // Wait if LCD busy
 WriteCmdXLCD(SHIFT_DISP_LEFT); // Entry Mode
 // Set DD Ram address to 0
 while(BusyXLCD());			 // Wait if LCD busy
 SetDDRamAddr(0x80);			 // Set Display data ram address to 0
 return;
}
/* SetCGRamAddr
* Sets the character generator address
*/
/********************************************************************
*	 Function Name: SetCGRamAddr							 *
*	 Return Value: void									 *
*	 Parameters:	 CGaddr: character generator ram address	 *
*	 Description: This routine sets the character generator *
*					 address of the Hitachi HD44780 LCD		 *
*					 controller. The user must check to see if *
*					 the LCD controller is busy before calling *
*					 this routine.							 *
********************************************************************/
void SetCGRamAddr(unsigned char CGaddr)
{
							 // Upper nibble interface
 TRIS_DATA_PORT &= 0x0f;				 // Make nibble input
 DATA_PORT &= 0x0f;					 // and write upper nibble
 DATA_PORT |= ((CGaddr | 0b01000000) & 0xf0);
 RW_PIN = 0;							 // Set control signals
 RS_PIN = 0;
 DelayFor18TCY();
 E_PIN = 1;							 // Clock cmd and address in
 DelayFor18TCY();
 E_PIN = 0;
 DATA_PORT &= 0x0f;					 // Write lower nibble
 DATA_PORT |= ((CGaddr<<4)&0xf0);
 DelayFor18TCY();
 E_PIN = 1;							 // Clock cmd and address in
 DelayFor18TCY();
 E_PIN = 0;

 TRIS_DATA_PORT |= 0xf0;				 // Make inputs
 return;
}
/* SetDDRamAddr
* Sets the display data address
*/
/********************************************************************
*	 Function Name: SetDDRamAddr							 *
*	 Return Value: void									 *
*	 Parameters:	 CGaddr: display data address			 *
*	 Description: This routine sets the display data address *
*					 of the Hitachi HD44780 LCD controller. The *
*					 user must check to see if the LCD controller*
*					 is busy before calling this routine.	 *
********************************************************************/
void SetDDRamAddr(unsigned char DDaddr)
{
									 // 4-bit interface
							 // Upper nibble interface
 TRIS_DATA_PORT &= 0x0f;				 // Make port output
 DATA_PORT &= 0x0f;					 // and write upper nibble
 DATA_PORT |= ((DDaddr | 0b10000000) & 0xf0);
 RW_PIN = 0;							 // Set control bits
 RS_PIN = 0;
 DelayFor18TCY();
 E_PIN = 1;							 // Clock the cmd and address in
 DelayFor18TCY();
 E_PIN = 0;
						 // Upper nibble interface
 DATA_PORT &= 0x0f;					 // Write lower nibble
 DATA_PORT |= ((DDaddr<<4)&0xf0);
 DelayFor18TCY();
 E_PIN = 1;							 // Clock the cmd and address in
 DelayFor18TCY();
 E_PIN = 0;
						 // Upper nibble interface
 TRIS_DATA_PORT |= 0xf0;				 // Make port input
 return;
}
/* BusyXLCD
* Returns the busy status of the LCD
*/
/********************************************************************
*	 Function Name: BusyXLCD								 *
*	 Return Value: char: busy status of LCD controller		 *
*	 Parameters:	 void									 *
*	 Description: This routine reads the busy status of the *
*					 Hitachi HD44780 LCD controller.			 *
********************************************************************/
unsigned char BusyXLCD(void)
{
 RW_PIN = 1;					 // Set the control bits for read
 RS_PIN = 0;
 DelayFor18TCY();
 E_PIN = 1;					 // Clock in the command
 DelayFor18TCY();
					 // Upper nibble interface
 if(DATA_PORT&0x80)
 {
		 E_PIN = 0;			 // Reset clock line
		 DelayFor18TCY();
		 E_PIN = 1;			 // Clock out other nibble
		 DelayFor18TCY();
		 E_PIN = 0;
		 RW_PIN = 0;			 // Reset control line
		 return 1;			 // Return TRUE
 }
 else						 // Busy bit is low
 {
		 E_PIN = 0;			 // Reset clock line
		 DelayFor18TCY();
		 E_PIN = 1;			 // Clock out other nibble
		 DelayFor18TCY();
		 E_PIN = 0;
		 RW_PIN = 0;			 // Reset control line
		 return 0;			 // Return FALSE
 }
}
/* ReadAddrXLCD
* Reads the current address
*/
/*********************************************************************
*	 Function Name: ReadAddrXLCD								 *
*	 Return Value: char: address from LCD controller		 *
*	 Parameters:	 void										 *
*	 Description: This routine reads an address byte from the *
*					 Hitachi HD44780 LCD controller. The user	 *
*					 must check to see if the LCD controller is *
*					 busy before calling this routine. The address*
*					 is read from the character generator RAM or *
*					 the display data RAM depending on what the *
*					 previous SetxxRamAddr routine was called. *
*********************************************************************/
unsigned char ReadAddrXLCD(void)
{
 char data;					 // Holds the data retrieved from the LCD
						 // 4-bit interface
 RW_PIN = 1;					 // Set control bits for the read
 RS_PIN = 0;
 DelayFor18TCY();
 E_PIN = 1;					 // Clock data out of the LCD controller
 DelayFor18TCY();
					 // Upper nibble interface
 data = DATA_PORT&0xf0;		 // Read the nibble into the upper nibble of data
 E_PIN = 0;					 // Reset the clock
 DelayFor18TCY();
 E_PIN = 1;					 // Clock out the lower nibble
 DelayFor18TCY();
					 // Upper nibble interface
 data |= (DATA_PORT>>4)&0x0f; // Read the nibble into the lower nibble of data
 E_PIN = 0;
 RW_PIN = 0;					 // Reset the control lines
 return (data&0x7f);			 // Return the address, Mask off the busy bit
}

/* ReadDataXLCD
* Reads a byte of data
*/
/********************************************************************
*	 Function Name: ReadDataXLCD							 *
*	 Return Value: char: data byte from LCD controller		 *
*	 Parameters:	 void									 *
*	 Description: This routine reads a data byte from the	 *
*					 Hitachi HD44780 LCD controller. The user *
*					 must check to see if the LCD controller is *
*					 busy before calling this routine. The data *
*					 is read from the character generator RAM or *
*					 the display data RAM depending on what the *
*					 previous SetxxRamAddr routine was called. *
********************************************************************/
char ReadDataXLCD(void)
{
 char data;
							 // 4-bit interface
 RW_PIN = 1;
 RS_PIN = 1;
 DelayFor18TCY();
 E_PIN = 1;					 // Clock the data out of the LCD
 DelayFor18TCY();
					 // Upper nibble interface
 data = DATA_PORT&0xf0;		 // Read the upper nibble of data
 E_PIN = 0;					 // Reset the clock line
 DelayFor18TCY();
 E_PIN = 1;					 // Clock the next nibble out of the LCD
 DelayFor18TCY();
					 // Upper nibble interface
 data |= (DATA_PORT>>4)&0x0f; // Read the lower nibble of data
 E_PIN = 0;									
 RS_PIN = 0;					 // Reset the control bits
 RW_PIN = 0;
 return(data);				 // Return the data byte
}

/* WriteCmdXLCD
* Writes a command to the LCD
*/
/********************************************************************
*	 Function Name: WriteCmdXLCD							 *
*	 Return Value: void									 *
*	 Parameters:	 cmd: command to send to LCD				 *
*	 Description: This routine writes a command to the Hitachi*
*					 HD44780 LCD controller. The user must check *
*					 to see if the LCD controller is busy before *
*					 calling this routine.					 *
********************************************************************/
void WriteCmdXLCD(unsigned char cmd)
{
						 // 4-bit interface
					 // Upper nibble interface
 TRIS_DATA_PORT &= 0x0f;
 DATA_PORT &= 0x0f;
 DATA_PORT |= cmd&0xf0;
 RW_PIN = 0;					 // Set control signals for command
 RS_PIN = 0;
 DelayFor18TCY();
 E_PIN = 1;					 // Clock command in
 DelayFor18TCY();
 E_PIN = 0;
					 // Upper nibble interface
 DATA_PORT &= 0x0f;
 DATA_PORT |= (cmd<<4)&0xf0;
 DelayFor18TCY();
 E_PIN = 1;					 // Clock command in
 DelayFor18TCY();
 E_PIN = 0;
				 // Make data nibble input
 TRIS_DATA_PORT |= 0xf0;
 return;
}
void WriteCmd8bit(unsigned char cmd)
{
						 // 4-bit interface
					 // Upper nibble interface
 TRIS_DATA_PORT &= 0x0f;
 DATA_PORT &= 0x0f;
 DATA_PORT |= cmd&0xf0;
 RW_PIN = 0;					 // Set control signals for command
 RS_PIN = 0;
 DelayFor18TCY();
 E_PIN = 1;					 // Clock command in
 DelayFor18TCY();
 E_PIN = 0;
 TRIS_DATA_PORT |= 0xf0;
 return;
}
/* WriteDataXLCD
* Writes a data byte to the LCD
*/
/********************************************************************
*	 Function Name: WriteDataXLCD							 *
*	 Return Value: void									 *
*	 Parameters:	 data: data byte to be written to LCD	 *
*	 Description: This routine writes a data byte to the	 *
*					 Hitachi HD44780 LCD controller. The user *
*					 must check to see if the LCD controller is *
*					 busy before calling this routine. The data *
*					 is written to the character generator RAM or*
*					 the display data RAM depending on what the *
*					 previous SetxxRamAddr routine was called. *
********************************************************************/
void WriteDataXLCD(char data)
{
					 // Upper nibble interface
 TRIS_DATA_PORT &= 0x0f;
 DATA_PORT &= 0x0f;
 DATA_PORT |= data&0xf0;
 RS_PIN = 1;					 // Set control bits
 RW_PIN = 0;
 DelayFor18TCY();
 E_PIN = 1;					 // Clock nibble into LCD
 DelayFor18TCY();
 E_PIN = 0;
					 // Upper nibble interface
 DATA_PORT &= 0x0f;
 DATA_PORT |= ((data<<4)&0xf0);
 DelayFor18TCY();
 E_PIN = 1;					 // Clock nibble into LCD
 DelayFor18TCY();
 E_PIN = 0;
					 // Upper nibble interface
 TRIS_DATA_PORT |= 0xf0;
 return;
}
/* putsXLCD
* Writes a string of characters to the LCD
*/
/********************************************************************
*	 Function Name: putsXLCD
*	 Return Value: void
*	 Parameters:	 buffer: pointer to string
*	 Description: This routine writes a string of bytes to the
*					 Hitachi HD44780 LCD controller. The user
*					 must check to see if the LCD controller is
*					 busy before calling this routine. The data
*					 is written to the character generator RAM or
*					 the display data RAM depending on what the
*					 previous SetxxRamAddr routine was called.
********************************************************************/
void putsXLCD(char *buffer)
{
 while(*buffer)				 // Write data to LCD up to null
 {
		 while(BusyXLCD());	 // Wait while LCD is busy
		 WriteDataXLCD(*buffer); // Write character to LCD
		 buffer++;			 // Increment buffer
 }
 return;
}
/* putrsXLCD
* Writes a string of characters in ROM to the LCD
*/
/********************************************************************
*	 Function Name: putrsXLCD
*	 Return Value: void
*	 Parameters:	 buffer: pointer to string
*	 Description: This routine writes a string of bytes to the
*					 Hitachi HD44780 LCD controller. The user
*					 must check to see if the LCD controller is
*					 busy before calling this routine. The data
*					 is written to the character generator RAM or
*					 the display data RAM depending on what the
*					 previous SetxxRamAddr routine was called.
********************************************************************/
void putrsXLCD(const rom char *buffer)
{
 while(*buffer)				 // Write data to LCD up to null
 {
		 while(BusyXLCD());	 // Wait while LCD is busy
		 WriteDataXLCD(*buffer); // Write character to LCD
		 buffer++;			 // Increment buffer
 }
 return;
}
/* User defines these routines according to the oscillator frequency */

#endif

П.С. А где настраиваются пины для D4, D5, D6, D7 в этой библиотеке ? Я вот всё пока никак понять не могу.

Код и библиотеку ( bootlcd.h ) брал на сайте в первом сообщении.

Спасибо !

post-195350-0-08909800-1468256471_thumb.jpg

post-195350-0-79991600-1468256502_thumb.jpg

post-195350-0-46866200-1468256504_thumb.png

post-195350-0-08041200-1468256505_thumb.png

Изменено пользователем IMXO
Ссылка на комментарий
Поделиться на другие сайты

Выбираем схему BMS для корректной работы литий-железофосфатных (LiFePO4) аккумуляторов

 Обязательным условием долгой и стабильной работы Li-FePO4-аккумуляторов, в том числе и производства EVE Energy, является применение специализированных BMS-микросхем. Литий-железофосфатные АКБ отличаются такими характеристиками, как высокая многократность циклов заряда-разряда, безопасность, возможность быстрой зарядки, устойчивость к буферному режиму работы и приемлемая стоимость. Но для этих АКБ, также как и для других, очень важен контроль процесса заряда и разряда, а специализированных микросхем для этого вида аккумуляторов не так много. Инженеры КОМПЭЛ подготовили список имеющихся микросхем и возможных решений от разных производителей. Подробнее>>

Реклама: АО КОМПЭЛ, ИНН: 7713005406, ОГРН: 1027700032161

Alex, большое спасибо, пока пытаюсь, но пока всё молчит. Сам мк работает - точно. Пока не пойму косяк. Ножки после lcd_init(); lcd_clear(); все минусе, то есть программа их определила, а также ножка RS положительна всё время. Больше картина не меняется.

Для тестирования вставил пока фрагменты из Вашего собственного примера.

#include "config_bits.h"
#include <stdio.h>
#include <stdlib.h>
#include <timers.h>
#include <string.h>
#include "lcd.h"
#include "lcd.c"
void high_isr (void);
#pragma code high_vector = 0x08
void interrupt_at_high_vector(void)
{
_asm GOTO high_isr _endasm
}
static int ms = 0;
#pragma interrupt high_isr
void high_isr (void) {

if (INTCONbits.TMR0IF){
 INTCONbits.TMR0IF = 0;				
 TMR0H = 0xF6;
 TMR0L = 0x3C;
 ms++;
}
}
static int o = 0;
char lcd_buff[16];
char arr_cgram[8]={0b00010,0b00101,0b00101,0b00010,};
void main (void) {

TRISA = 0x00;
PORTA = 0x00;
TRISB = 0xF0;
PORTB = 0x00;
TRISC = 0x00;
PORTC = 0x00;
TRISD = 0x00;
PORTD = 0x00;
TRISE = 0x00;
PORTE = 0x00;

ADCON1 = 0x0F;
T0CON = 0b10001000; // 10000101 TMR0ON T0PS2 T0PS0
TMR0H = 0xF6;
TMR0L = 0x3C;
INTCON = 0x20;			
INTCON2 = 0x04;
RCONbits.IPEN = 1;				
INTCONbits.GIEH = 1;

DelayMs(1000);
lcd_init();
lcd_clear();
DelayMs(10);
lcd_cgram((char*)arr_cgram, 0x01);
lcd_gotoxy(0,0);
sprintf(lcd_buff, "25.5");
lcd_puts(lcd_buff);
lcd_putch(0x01);
lcd_putch('C');

while (1) {
 if ( ms == 1000 ) {
 if ( o == 0 ) { PORTB = 0x0E; o = 1; } else
 if ( o == 1 ) { PORTB = 0x0D; o = 2; } else
 if ( o == 2 ) { PORTB = 0x0B; o = 3; } else
 if ( o == 3 ) { PORTB = 0x07; o = 4; } else
 if ( o == 4 ) { PORTB = 0x0B; o = 5; } else
 if ( o == 5 ) { PORTB = 0x0D; o = 0; }
 PORTCbits.RC5 = !PORTCbits.RC5;
 ms = 0;
 }
}
}

Файл "lcd.h":

#ifndef	 _LCD_H_
#define	 _LCD_H_
//***************************************************//
//-------------------------------------------------------------------------//
#define X_FREQ	 10				
#if	 defined(__PICC__)		 /* HI-TECH PICC, XC8 */
#define RS_PIN	 RB0				 // RS
#define RS_TRIS	 TRISB0			 //
#define EN_PIN	 RB1				 // EN
#define EN_TRIS	 TRISB1			 //
#define D4_PIN	 RB2				 // D4
#define D4_TRIS	 TRISB2			 //
#define D5_PIN	 RB3				 // D5
#define D5_TRIS	 TRISB3			 //
#define D6_PIN	 RB4				 // D6
#define D6_TRIS	 TRISB4			 //
#define D7_PIN	 RB5				 // D7
#define D7_TRIS	 TRISB5			 //
#elif defined(__PICC18__)		 /* HI-TECH PICC_18 */
#define RS_PIN	 LATB0			 // RS
#define RS_TRIS	 TRISB0			 //
#define EN_PIN	 LATB1			 // EN
#define EN_TRIS	 TRISB1			 //
#define D4_PIN	 LATB2			 // D4
#define D4_TRIS	 TRISB2			 //
#define D5_PIN	 LATB3			 // D5
#define D5_TRIS	 TRISB3			 //
#define D6_PIN	 LATB4			 // D6
#define D6_TRIS	 TRISB4			 //
#define D7_PIN	 LATB5			 // D7
#define D7_TRIS	 TRISB5			 //
#elif defined(__18CXX)			 /* MCC_18		 */
#define RS_PIN	 LATDbits.LATD0	 // RS
#define RS_TRIS	 TRISDbits.TRISD0 //
#define EN_PIN	 LATDbits.LATD1	 // EN
#define EN_TRIS	 TRISDbits.TRISD1 //
#define D4_PIN	 LATDbits.LATD2	 // D4
#define D4_TRIS	 TRISDbits.TRISD2 //
#define D5_PIN	 LATDbits.LATD3	 // D5
#define D5_TRIS	 TRISDbits.TRISD3 //
#define D6_PIN	 LATDbits.LATD4	 // D6
#define D6_TRIS	 TRISDbits.TRISD4 //
#define D7_PIN	 LATDbits.LATD5	 // D7
#define D7_TRIS	 TRISDbits.TRISD5 //
#else
#endif
#define LCD_MODE_1x8 0
#define LCD_MODE_1x16_A 0
#define LCD_MODE_1x16_B 0
#define LCD_MODE_1x40 0
#define LCD_MODE_2x8 0
#define LCD_MODE_2x12 0
#define LCD_MODE_2x16 1
#define LCD_MODE_2x20 0
#define LCD_MODE_2x24 0
#define LCD_MODE_2x40 0
#define LCD_MODE_4x16 0
#define LCD_MODE_4x20 0
#define LCD_MODE_4x24 0
#define LCD_MODE_4x40 0
extern void lcd_init(void);
extern void lcd_clear(void);
extern void lcd_gotoxy(char, char);
extern void lcd_puts(char *);
extern void lcd_putch(char);
extern void lcd_cgram(char *, unsigned char);
//-------------------------------------------------------------------------//
#define DelayUs(x) { unsigned int i=x/(40/X_FREQ) ; while(i--); }
#define DelayMs(x) { unsigned int i=x; while(i--){unsigned int a=830/(40/X_FREQ); while(a--); } }
//***************************************************//
#endif

Catcatcat, тоже, огромное спасибо, но Ваша библиотека под XC8 и HI-TECH компиляторы. Попозже - попробую.

post-195350-0-12107000-1468262627_thumb.png

Изменено пользователем IMXO
Ссылка на комментарий
Поделиться на другие сайты

Ошибка была в том, что пины на LCD D0, D1, D2, D3 я забыл подключить к отрицательному выходу. Теперь всё работает. Ёмаё ( Наше ). Из-за этого создал целую тему ... расписал ... ёмаё. Столько времени потерял ( эх ). Бывает же-е-е-е ...

Я Вам очень благодарен и признателен. Alex мне уже не раз помогает, за что ему отдельное Спасибо ! Дай Бог Вам Всем Счастья И Здоровья !

Это Ваш аккаунт, на том сайте ?

Catcatcat, видел ваши Видео в YouTube. У Вас сногсшибательные проекты. Вы - молодец ! В Том Же Духе ! ( Ну оч красивая светомузыка !!! )

Рабочий код ( Убрал всё лишнее ):

#include "config_bits.h"
#include <stdio.h>
#include <stdlib.h>
#include <timers.h>
#include <string.h>
#include "lcd.h"
#include "lcd.c"
char lcd_buff[16];
char arr_cgram[8]={0b00010,0b00101,0b00101,0b00010,};
void main (void) {

TRISA = 0x00;
PORTA = 0x00;
TRISB = 0xF0;
PORTB = 0x00;
TRISC = 0x00;
PORTC = 0x00;
TRISD = 0x00;
PORTD = 0x00;
TRISE = 0x00;
PORTE = 0x00;

ADCON1 = 0x0F;

DelayMs(1000);
lcd_init();
lcd_clear();
DelayMs(10);
lcd_cgram((char*)arr_cgram, 0x01);
lcd_gotoxy(0,0);
sprintf(lcd_buff, "25.5");
lcd_puts(lcd_buff);
lcd_putch(0x01);
lcd_putch('C');

while (1) {
}
}

Файл "lcd.h":

/****************************************************/
/* Файл lcd.h									 */
/* Модуль для работы с LCD						 */
/* Автор:	 Alex, http://ChipMk.ru			 */
/* E-mail:	 al.kl@list.ru					 */
/* Компиляторы: HI-TECH PICC(18), Microchp C18, XC8 */
/****************************************************/
#ifndef	 _LCD_H_
#define	 _LCD_H_
//***************************************************//
//-------------------------------------------------------------------------//
#define X_FREQ	 20					 // Тактовая частота МК (MHz)
//-------- Пины -----------------------------------------------------------//
#if	 defined(__PICC__)		 /* HI-TECH PICC, XC8 */
#define RS_PIN	 RB0				 // RS
#define RS_TRIS	 TRISB0			 //
#define EN_PIN	 RB1				 // EN
#define EN_TRIS	 TRISB1			 //
#define D4_PIN	 RB2				 // D4
#define D4_TRIS	 TRISB2			 //
#define D5_PIN	 RB3				 // D5
#define D5_TRIS	 TRISB3			 //
#define D6_PIN	 RB4				 // D6
#define D6_TRIS	 TRISB4			 //
#define D7_PIN	 RB5				 // D7
#define D7_TRIS	 TRISB5			 //
#elif defined(__PICC18__)		 /* HI-TECH PICC_18 */
#define RS_PIN	 LATB0			 // RS
#define RS_TRIS	 TRISB0			 //
#define EN_PIN	 LATB1			 // EN
#define EN_TRIS	 TRISB1			 //
#define D4_PIN	 LATB2			 // D4
#define D4_TRIS	 TRISB2			 //
#define D5_PIN	 LATB3			 // D5
#define D5_TRIS	 TRISB3			 //
#define D6_PIN	 LATB4			 // D6
#define D6_TRIS	 TRISB4			 //
#define D7_PIN	 LATB5			 // D7
#define D7_TRIS	 TRISB5			 //
#elif defined(__18CXX)			 /* MCC_18		 */
#define RS_PIN	 LATDbits.LATD0	 // RS
#define RS_TRIS	 TRISDbits.TRISD0 //
#define EN_PIN	 LATDbits.LATD1	 // EN
#define EN_TRIS	 TRISDbits.TRISD1 //
#define D4_PIN	 LATDbits.LATD2	 // D4
#define D4_TRIS	 TRISDbits.TRISD2 //
#define D5_PIN	 LATDbits.LATD3	 // D5
#define D5_TRIS	 TRISDbits.TRISD3 //
#define D6_PIN	 LATDbits.LATD4	 // D6
#define D6_TRIS	 TRISDbits.TRISD4 //
#define D7_PIN	 LATDbits.LATD5	 // D7
#define D7_TRIS	 TRISDbits.TRISD5 //
#else
#endif
//------------------------- Разрешение экрана ----------------------------//
#define LCD_MODE_1x8 0
#define LCD_MODE_1x16_A 0
#define LCD_MODE_1x16_B 0
#define LCD_MODE_1x40 0
#define LCD_MODE_2x8 0
#define LCD_MODE_2x12 0
#define LCD_MODE_2x16 1
#define LCD_MODE_2x20 0
#define LCD_MODE_2x24 0
#define LCD_MODE_2x40 0
#define LCD_MODE_4x16 0
#define LCD_MODE_4x20 0
#define LCD_MODE_4x24 0
#define LCD_MODE_4x40 0
//------------------------- Прототипы -------------------------------------//
extern void lcd_init(void);
extern void lcd_clear(void);
extern void lcd_gotoxy(char, char);
extern void lcd_puts(char *);
extern void lcd_putch(char);
extern void lcd_cgram(char *, unsigned char);
//-------------------------------------------------------------------------//
#define DelayUs(x) { unsigned int i=x/(40/X_FREQ) ; while(i--); }
#define DelayMs(x) { unsigned int i=x; while(i--){unsigned int a=830/(40/X_FREQ); while(a--); } }
//***************************************************//
#endif	 // _LCD_H_

П.С. Alex, с вашей кодировкой ещё игрался )). Но, под рукой оказался старый, добрый Sublime Text и всё теперь - как нужно ! Спасибо !!

post-195350-0-64348100-1468269433_thumb.png

Изменено пользователем IMXO
Ссылка на комментарий
Поделиться на другие сайты

Странно, но МК почему-то перезагружается через 5-15 минут, а через 40-60 минут просто останавливается и экран пустой и светодиод не моргает.

Написал маленький таймер для того, чтоб высчитать HIGH и LOW байты под 1 секунду. Если его принудительно перезапустить ( обесточить ), то вначале всё прекрасно работает.

Код:

#include "config_bits.h"
#include <stdio.h>
#include <stdlib.h>
#include <timers.h>
#include <string.h>
#include "lcd.h"
#include "lcd.c"
void high_isr (void);
#pragma code high_vector = 0x08
void interrupt_at_high_vector(void)
{
_asm GOTO high_isr _endasm
}
static int ms = 0;
static int s = 0;
char S[];
static int m = 0;
char M[];
static int h = 0;
char H[];
#pragma interrupt high_isr
void high_isr (void) {
if (INTCONbits.TMR0IF){
 INTCONbits.TMR0IF = 0;				
 TMR0H = 0xF6;
 TMR0L = 0x3C;
 ms++;
}
}
static int o = 0;
char lcd_buff[16];
char time_buff[8];
char lcd_time( int ss ) {
if ( ss > 59 ) { s = 0; m++; }
if ( m > 59 ) { m = 0; h++; }
if ( h > 23 ) { s = 0; m = 0; h = 0; }
if ( ss < 10 ) { sprintf(S, "0%d", s); } else { sprintf(S, "%d", s); }
if ( m < 10 ) { sprintf(M, "0%d", m); } else { sprintf(M, "%d", m); }
if ( h < 10 ) { sprintf(H, "0%d", h); } else { sprintf(H, "%d", h); }
sprintf(lcd_buff, "%02d:%02d:%02d", h, m, s);
}
void main (void) {

TRISA = 0x00;
PORTA = 0x00;
TRISB = 0xF0;
PORTB = 0x00;
TRISC = 0x00;
PORTC = 0x00;
TRISD = 0x00;
PORTD = 0x00;
TRISE = 0x00;
PORTE = 0x00;

ADCON1 = 0x0F;
T0CON = 0b10001000;
TMR0H = 0xF6;
TMR0L = 0x3C;
INTCON = 0x20;			
INTCON2 = 0x04;
RCONbits.IPEN = 1;				
INTCONbits.GIEH = 1;

DelayMs(10);
lcd_init();
lcd_clear();
DelayMs(10);
lcd_gotoxy(0,5);
sprintf(lcd_buff, "STARTED");
lcd_puts(lcd_buff);
DelayMs(100);
while (1) {
 if ( ms == 1000 ) {
 PORTCbits.RC5 = !PORTCbits.RC5;
 s++;
 lcd_clear();
 lcd_time( s );
 lcd_gotoxy(0,4);
 lcd_puts(lcd_buff);
 ms = 0;
 }
}
}

Из-за чего такое может быть ? Может ли так быть из-за отсутствия конденсатора на 0.1мкф между + и - ? Спасибо !

post-195350-0-59284100-1468314572_thumb.jpg

Изменено пользователем IMXO
Ссылка на комментарий
Поделиться на другие сайты

Даже если МК остановится, экран пустым не будет. На нём останется последняя информация.

Эм....

char S[];
char M[];
char H[];

А какого размера тут массивы ? Так нельзя делать :vava:

И ещё. Вот это :

if ( ms == 1000 )

лучше заменить на :

if ( ms >= 1000 )

Ссылка на комментарий
Поделиться на другие сайты

Переменные поменял. Ветвление тоже.

Я вот его сейчас запустил ( утром ), работает. Показывает уже 01:00:13 ( Аля час ), работает. Пока не перезапускался. Ничего не менял. Просто пошелестил проводами этими ( На монтажной ).

Перезапускался он ночью примерно 5-6 раз за час. Не знаю почему. Догадываюсь, что это из-за питания. Как думаете 0.1мкф между + и - поможет ? Я его тогда поеду и куплю сегодня. Что ещё можно добавить для стабильной работы МК ?

Ссылка на комментарий
Поделиться на другие сайты

0.1 на питании - обязателен. Причём чем ближе к выводам питания, тем лучше. Но это уже учтёте когда будете делать плату.

Вообще, советую для экспериментов сделать отладочную платку.

Ссылка на комментарий
Поделиться на другие сайты

Любую, просто сами придумайте. МК, необходимая обвязка, с краю выводы с пинов МК, выводы для программатора. Можно всякие кнопочки там добавить, и т.д... На ней же, сразу и кондёров натыкаете.

По защитам и разводкам плат, я - не помощник, к сожалению.

Ссылка на комментарий
Поделиться на другие сайты

Присоединяйтесь к обсуждению

Вы можете написать сейчас и зарегистрироваться позже. Если у вас есть аккаунт, авторизуйтесь, чтобы опубликовать от имени своего аккаунта.
Примечание: Ваш пост будет проверен модератором, прежде чем станет видимым.

Гость
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Ответить в этой теме...

×   Вставлено с форматированием.   Восстановить форматирование

  Разрешено использовать не более 75 эмодзи.

×   Ваша ссылка была автоматически встроена.   Отображать как обычную ссылку

×   Ваш предыдущий контент был восстановлен.   Очистить редактор

×   Вы не можете вставлять изображения напрямую. Загружайте или вставляйте изображения по ссылке.

Загрузка...
  • Последние посетители   0 пользователей онлайн

    • Ни одного зарегистрированного пользователя не просматривает данную страницу
×
×
  • Создать...