Jump to content
ELFORUM - Forumul electronistilor

Probleme afisare pic18f4523

Guest dorianetegan

Recommended Posts

Guest dorianetegan

Am incercat sa realizez din diferite informatii un program de afisare dar tot nu imi afiseaza + am mai pus un buzzer pe pinul RC5. Am programat PICul vand stau s verific cu buzzerul pinul RC5 nu merge cand din greseala ating pinul RC6(Tx) si reating tinul RC5 merge...numai ca afisarea nu merge care ar fi problema?

/*  * File:   main.c * Author: Dorian * * Created on 01 iulie 2012, 12:22 */#include	<htc.h>#include	<stdio.h>#include	<string.h>#include	<stdlib.h>#pragma config OSC = HS#pragma config WDT = OFF#pragma config LVP = ON#define _XTAL_FREQ 16000000// LCD command definitions#define LCD_WAKE 		0x03 	// Wake up the display#define LCD_8BIT 		0x38	// 8 bit / 2x16 caractere#define LCD_4BIT 		0x02	// 4 bit / 2x16 caractere#define LCD_ENDISP 		0x08	// Enable the display (no cursor)#define LCD_CLR 		0x01	// Clear display and home cursor#define LCD_CURRIGHT 	0x06	// Move cursor right on character write#define LCD_DISPON 		0x0c	// Turn on the display#define LCD_DISPOFF		0x00	// Turn off the display#define LCD_DDSET		0x80	// Set the DDRAM#define CMD_REG 		0		// Command register selection#define DATA_REG 		1		// Data register selection// Defines for LCD firmware#define LCD_EN	RB1#define LCD_RS	RB0#define LCD_DB4	RD4#define LCD_DB5	RD5#define LCD_DB6	RD6#define LCD_DB7	RD7unsigned char lcda;unsigned char lcdb;/* *	Delay functions for HI-TECH C on the PIC18 * *	Functions available: *		DelayUs(x)	Delay specified number of microseconds *		DelayMs(x)	Delay specified number of milliseconds * *	Note that there are range limits: *	- on small values of x (i.e. x<10), the delay becomes less *	accurate. DelayUs is accurate with xtal frequencies in the * 	range of 4-16MHZ, where x must not exceed 255. *	For xtal frequencies > 16MHz the valid range for DelayUs *	is even smaller - hence affecting DelayMs. *	To use DelayUs it is only necessary to include this file. *	To use DelayMs you must include delay.c in your project. * *	Set the crystal frequency in the CPP predefined symbols list *	on the PICC-18 commmand line, e.g. *	picc18 -DXTAL_FREQ=4MHZ * *	or *	picc18 -DXTAL_FREQ=100KHZ * *	Note that this is the crystal frequency, the CPU clock is *	divided by 4. * *	MAKE SURE this code is compiled with full optimization!!!*/#define	MHZ	*1#ifndef	XTAL_FREQ#define	XTAL_FREQ	16MHZ		/* Crystal frequency in MHz */#endif#if	XTAL_FREQ < 8MHZ#define	uS_CNT 	238			/* 4x to make 1 mSec */#endif#if	XTAL_FREQ == 8MHZ#define uS_CNT  244#endif#if	XTAL_FREQ > 8MHZ#define uS_CNT  246#endif#define FREQ_MULT	(XTAL_FREQ)/(4MHZ)#define	DelayUs(x)	{ unsigned char _dcnt; \			  if(x>=4) _dcnt=(x*(FREQ_MULT)/2); \			  else _dcnt=1; \			  while(--_dcnt > 0) \				{\				asm("nop");\				asm("nop");\				continue; }\		}extern void intarziere_ms(unsigned char cnt);void intarziere_ms(unsigned char cnt) {	unsigned char i;	while (cnt--) {		i=4;		while(i--) {			DelayUs(uS_CNT);	/* Adjust for error */		} ;	} ;}// Protypes...// Write a byte to the LCD in 4 bit modevoid scrielcd(unsigned char adress, unsigned char c);// Clear and home the LCDvoid golestelcdul(void);// Write a string of characters to the LCDvoid punecar(const char * s);// Go to the specified positionvoid lcdgt(int x, int y);// Intialise the LCD - call before anything elsevoid lcdInit(void);// Output a single charactervoid lcdPutch(char c);// Set the display state (on or off)void lcdDisplayState(int state);// write a nybble to the portvoid lcdWriteNybble(unsigned char nybble){	// This routine is required because the LCD data bus	// is not connected on a continuous sequence of port pins	// so we have to break it up and write to the pins	// individually.	// Write the nybble to the LCD databus pins	if (nybble & 0b00000001) LCD_DB4 = 1; else LCD_DB4 = 0;	if (nybble & 0b00000010) LCD_DB5 = 1; else LCD_DB5 = 0;	if (nybble & 0b00000100) LCD_DB6 = 1; else LCD_DB6 = 0;	if (nybble & 0b00001000) LCD_DB7 = 1; else LCD_DB7 = 0;}// write a byte to the LCD in 4 bit modevoid scrielcd(unsigned char address, unsigned char c){	LCD_RS = address;	intarziere_ms(10);	// Write the 4 bits non-distructively to the port	lcdWriteNybble((c >> 4) & 0x0F);	// Toggle the clock bit	LCD_EN = 1;	intarziere_ms(10);	LCD_EN = 0;	intarziere_ms(10);	// Write the 4 bits non-distructively to the port	lcdWriteNybble(c & 0x0F);	// Toggle the clock bit	LCD_EN = 1;	intarziere_ms(100);	intarziere_ms(100);}// write one character to the LCDvoid lcdPutch(char c){	// This routine needs updating so it monitors the cursor posiiton	LCD_RS = 1;	// write characters	scrielcd(DATA_REG, c);}void golestelcdul(void){	scrielcd(CMD_REG, LCD_CLR);	// Reset our internal cursor position	lcda = 0;	lcdb = 0;	// Delay	for (int counter = 0; counter < 200; counter++) intarziere_ms(50);}// Initialise the LCDvoid lcdInit(void){	int counter;	// Power up delay	for (counter = 0; counter < 1500; counter++) intarziere_ms(50);	LCD_EN = 0; // Set clock low	LCD_RS = CMD_REG; // Set RS to command register	// Set up the interface	lcdWriteNybble(LCD_WAKE);	LCD_EN = 1;	LCD_EN = 0;	for (counter = 0; counter < 500; counter++) intarziere_ms(50);	LCD_EN = 1;	LCD_EN = 0;	intarziere_ms(100);	LCD_EN = 1;	LCD_EN = 0;	intarziere_ms(100);	// Set the interfact to 4 bits	lcdWriteNybble(LCD_4BIT);	intarziere_ms(50);	LCD_EN = 1;	intarziere_ms(50);	LCD_EN = 0;	// Don't know what this does...	scrielcd(CMD_REG, 0x28);	// Enable display / hide cursor	scrielcd(CMD_REG, LCD_ENDISP);	// Clear the display and home the cursor	golestelcdul();	// Set the cursor movement direction to right	scrielcd(CMD_REG, LCD_CURRIGHT);	// Turn on display	scrielcd(CMD_REG, LCD_DISPON);	// Reset our internal cursor position	lcda = 0;	lcdb = 0;}void lcdDisplayState(int state){	if (state == 1) scrielcd(DATA_REG, LCD_DISPON);		else scrielcd(DATA_REG, LCD_DISPOFF);}// Move the cursor to the specified X,Yvoid lcdgt(int x, int y){	int offset;	// Select the correct line of the display	switch (y)	{		case 0: offset = 0x00;				break;		case 1: offset = 0x40;				break;		case 2: offset = 0x14;				break;		case 3: offset = 0x54;				break;	}	// Select the correct character of the line	offset += x;	// Send the command to the LCD	scrielcd(DATA_REG, LCD_DDSET | offset);	// Reset our internal cursor position	lcda = x;	lcdb = y;}// Output a string of characters to the displayvoid punecar(const char *s){	// Since the 2 line display is in the order line 1, line 2	// we need to read the current cursor position and control how the text is	// output, adjusting the cursor position as we go	int loop;	for (loop = 0; loop < strlen(s); loop++)	{		// Write the character to the LCD		scrielcd(DATA_REG, s[loop]);		lcda++;		// Have we reached the end of the line?		if (lcda == 15)		{			// Move to the start of the next line			lcda = 0;			lcdb++;			// If we are off the bottom of the screen			// go back to the top line			if (lcdb == 2) lcdb = 0;			// Adjust the cursor position on the LCD			lcdgt(lcda, lcdb);		}	}}void main(){    PORTD=0;    PORTB=0;    TRISD=0;    TRISB=0;    TRISC=0;    lcdInit();    lcdgt(0,0);    punecar("Distanta in m:");    lcdgt(7,1);    punecar("2.5");    while(1)    {       PORTCbits.RC5 = 1;       intarziere_ms(2000);    }    }/* * */
ar putea cineva sa-l testeze? sa-mi spuna daca merge L-am realizat in MPLAB cu ajutorul compilatorului HI-TECH PICC18
Link to comment
  • Replies 1
  • Created
  • Last Reply

Popular Days

Guest dorianetegan

Si daca fac trimitere la punecar(const char *s) cu ovariabila unsigned char imi da warning main.c:495 warning: illegal conversion of integer to pointer si mai imi da un warning la linia scrielcd(DATA_REG, s[loop]);-din functia punecar main.c:297 warning: "ROM" is positioned at address 0x0 and has had its address taken; pointer comparisons may be invalid

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.Terms of Use si Guidelines