Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

hitech c compiling error

Status
Not open for further replies.

giaanthunder

Newbie level 2
Joined
Jan 1, 2012
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,293
im having trouble when compiling with mplab 9.65
if you have freetime. can you show me the way you fix these error.
my code
Code:
#include <htc.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include "lcd4x20.h"
#include <string.h>


__CONFIG(HS & WDTDIS & PWRTEN & UNPROTECT & BORDIS & LVPDIS);
#define _XTAL_FREQ 4000000


	#define row0 RA0
	#define row1 RA1
	#define row2 RA2 
	#define row3 RA3 
	#define row4 RA4 
	#define row5 RA5
	#define col0 RB0 
	#define col1 RB1 
	#define col2 RB2 
	#define col3 RB3 
	#define col4 RB4
	#define col5 RB5 
	#define col6 RB6 
	#define col7 RB7

	const char KEYS[6][8] = {
							{"1","2","3","4","5","6","7","8"},
							{"q","w","e","r","t","y","9","0"},
							{"a","s","d","f","u","i","o","p"},
				 			{"z","x","c","g","h","j","k","l"},
							{"v","b","n","m",",",".","up","enter"},
							{"shift","ctrl"," ","alt","clr","left","down","right"}
							};
	const char CAPS[6][8] = {
							{"!","@","#","$","%","^","&","*"}, 		
							{"Q","W","E","R","T","Y","(",")"}, 	
						 	{"A","S","D","F","U","I","O","P"}, 	
						 	{"Z","X","C","G","H","J","K","L"},	
							{"V","B","N","M","<",">","up","enter"},
							{"shift","ctrl"," ","alt","clr","left","down","right"}
							};

	#define kbd_debounce_factor 60

char dat_line1[] = "\0";	// Noi dung can hien thi - Hang 1.
char dat_line2[] = "\0";	// Noi dung can hien thi - Hang 2.
char dat_line3[] = "\0";	// Noi dung can hien thi - Hang 3.
char dat_line4[] = "\0";	// Noi dung can hien thi - Hang 4.

char chuoi_hien_thi[] = "\0" //noi dung can hien thi


bit ALL_ROWS(void)
{						
	if(row0 && row1 && row2 && row3 && row4 && row5) 					
		return(0); 	
	else
		return(1); 	
} 

void kbd_init()
{
ADCON1= 0b00000111;
TRISA= 0xFF;
PORTA= 0xFF;
TRISB= 0x00;
PORTB= 0xFF;
}

char kbd_getc()		// Ham lay ma phim duoc nhan tren ban phim.
{ 
	static bit kbd_down = 0; 		// Bien chi thi da co nhan hay chua co nhan phim lan nao (Mac dinh = FALSE).
	char last_key[]; 		// Bien chua ma phim duoc nhan o lan nhan sau cung (Mac dinh = NULL).
	unsigned char col = 0;			// Bien thu tu cot duoc quet (Cot tich cuc, mac dinh = cot 0). 
	unsigned char row; 				// Bien thu tu hang co phim nhan (Hang tich cuc).
	char kchar[]; 			// Bien chua ma phim.
	unsigned char kbd_call_count; 	// Bien dem so lan goi quet phim de thuc hien chong doi.

	kchar[] = "\0"; 	// Bien chua ma phim duoc nhan (Mac dinh ban dau chua ky tu NULL).
	
	for(kbd_call_count = 0; kbd_call_count <= kbd_debounce_factor; kbd_call_count++) 	// Thuc hien vong lap de chong doi phim nhan.
		{ 
		switch(col)
			{ 
			case 0:
		        col7 = 1; 
		        col6 = 1; 
		        col5 = 1; 
		        col4 = 1;
		        col3 = 1; 
		        col2 = 1; 
		        col1 = 1; 
		        col0 = 0; 
		        break; 
	    	case 1: 
		        col7 = 1; 
		        col6 = 1; 
		        col5 = 1; 
		        col4 = 1; 
		        col3 = 1; 
		        col2 = 1; 
		        col1 = 0; 
		        col0 = 1; 
		        break; 
			case 2:
		        col7 = 1; 
		        col6 = 1; 
		        col5 = 1; 
		        col4 = 1; 
		        col3 = 1; 
		        col2 = 0; 
		        col1 = 1; 
		        col0 = 1; 
		        break; 
			case 3:
		        col7 = 1; 
		        col6 = 1; 
		        col5 = 1; 
		        col4 = 1; 
		        col3 = 0; 
		        col2 = 1; 
		        col1 = 1; 
		        col0 = 1; 
		        break; 
			case 4:
		        col7 = 1; 
		        col6 = 1; 
		        col5 = 1; 
		        col4 = 0;
		        col3 = 1; 
		        col2 = 1; 
		        col1 = 1; 
		        col0 = 1; 
		        break; 
	    	case 5: 
		        col7 = 1; 
		        col6 = 1; 
		        col5 = 0; 
		        col4 = 1; 
		        col3 = 1; 
		        col2 = 1; 
		        col1 = 1; 
		        col0 = 1; 
		        break; 
			case 6:
		        col7 = 1; 
		        col6 = 0; 
		        col5 = 1; 
		        col4 = 1; 
		        col3 = 1; 
		        col2 = 1; 
		        col1 = 1; 
		        col0 = 1; 
		        break; 
			case 7:
		        col7 = 0; 
		        col6 = 1; 
		        col5 = 1; 
		        col4 = 1; 
		        col3 = 1; 
		        col2 = 1; 
		        col1 = 1; 
		        col0 = 1; 
		        break; 
			} 
	
		if(kbd_down) 	// Kiem tra xac nhan viec da co nhan hay chua nhan phim.
						// Neu chua nhan thi kiem tra phim nao se duoc nhan.
						// Neu da co phim nhan thi cho den khi phim da nhan duoc nha (buong ra).
			{ 		// Truong hop da co nhan phim (kbd_down = True) - Cho nha phim da nhan.
			if(!ALL_ROWS()) 	// Neu khong co phim nao duoc nhan (khong con giu phim nhan nua).
				{ 
				kbd_down = 0; 	// Xac nhan khong con phim nao duoc nhan (kbd_down = False). 
				kchar = last_key; 	// Lay ma phim duoc nhan truoc do.
				last_key = "\0"; 		// Cat ma phim (NULL) tuong ung khong nhan phim nao.
	        	} 
			} 
		else 			
			{ 		// Truong hop chua co phim nao nhan (kbd_down = False) - Kiem tra phim nao duoc nhan.
			if(ALL_ROWS()) 		// Neu truong hop CO bat ky phim nao duoc nhan
				{ 				// Kiem tra phim duoc nhan thuoc hang nao (Hang tich cuc).
				if(!row0) 		// Hang 0 tich cuc? (row0 = LOW).
					row = 0; 					// Hang 0.
				else if(!row1) 	// Hang 1 tich cuc? (row1 = LOW).
					row = 1; 					// Hang 1. 
				else if(!row2) 	// Hang 2 tich cuc? (row2 = LOW).
					row = 2;  				// Hang 2.
				else if(!row3) 	// Hang 3 tich cuc? (row3 = LOW).
					row = 3;  				// Hang 3.
				else if(!row4) 	// Hang 1 tich cuc? (row1 = LOW).
					row = 4; 					// Hang 1. 
				else if(!row5) 	// Hang 2 tich cuc? (row2 = LOW).
					row = 5;  				// Hang 2.

	
				last_key = KEYS[row][col]; 	// Lay ma phim dua vao hang (row) va cot (col) tich cuc.
											// Bo ma cua ban phim duoc thiet lap o dau chuong trinh.
				kbd_down = 1; 			// Xac nhan da co phim nhan (kbd_down = True).
				} 
			else 				// Neu truong hop KHONG CO phim nao duoc nhan.
				{ 				// Chuyen sang quet cot ke tiep.
				col++; 		// Tang bien quet cot -> chuyen sang quet cot ke tiep.
				if (col == 8) 	// Xu ly de chi quet 4 cot (tra ve quet cot dau tien).
					col = 0; 	// Cot 0.
				} 
			} 
		} 
	while (ALL_ROWS());	// Cho cho den khi khong con giu phim nua moi tra ve ma phim nhan.
	return(kchar); 	// Tra ve ma ASCII cua phim duoc nhan (bang ma duoc khai bao o dau chuong trinh).
}



void init_PORTC(void)
{
	PORTC = 0X00;
	TRISC = 0X00;
}

void init_PORTD(void)
{
	PORTD = 0X00;
	TRISD = 0X00;
}

void init_PORTE(void)
{
	PORTE = 0X00;
	TRISE = 0X00;
}

void main()
{
	char k[]="\0";

	init_PORTD();
	PORTD = 0x00;
	kbd_init();
	while(1) 	// Vong lap cho ngat.
		{ 
		k = kbd_getc(); 	// Thuc hien quet ban phim va lay ma phim.
		if(k!="\0") 			// Kiem tra co nhan phim (ma phim khac NULL).
			{
			strcpy(chuoi_hien_thi,k);
			kbd_getc()="\0";
			unsigned char i;
			int len=strlen(chuoi_hien_thi);
			if(len<61)
			{
			for(i=0;i<=19;i++)
				dat_line1[i]=chuoi_hien_thi[i];
			for(i=20;i<=39;i++)
				dat_line2[i]=chuoi_hien_thi[i];
			for(i=40;i<=58;i++)
				dat_line3[i]=chuoi_hien_thi[i];
			}
			else
			{
			for(i=len-59;i<=len-38;i++)
				dat_line1[i]=chuoi_hien_thi[i];
			for(i=len-39;i<=len-18;i++)
				dat_line2[i]=chuoi_hien_thi[i];
			for(i=len-19;i<=len-1;i++)
				dat_line3[i]=chuoi_hien_thi[i];			
			}
			lcd_puts("\f");						// Xoa man hinh LCD.
			for(i=0;i<=19;i++)
				{
				lcd_gotoxy(i,0);			// Xac dinh toa do hien thi cho hang 1.
				lcd_putc(dat_line1[i]);		// Lay ky tu hien thi tu chuoi 1 dua len C.LCD.
				lcd_gotoxy(i,1);			// Xac dinh toa do hien thi cho hang 2.
				lcd_putc(dat_line2[i]);		// Lay ky tu hien thi tu chuoi 2 dua len C.LCD.
				lcd_gotoxy(i,2);			// Xac dinh toa do hien thi cho hang 3.
				lcd_putc(dat_line3[i]);		// Lay ky tu hien thi tu chuoi 3 dua len C.LCD.
				lcd_gotoxy(i,3);			// Xac dinh toa do hien thi cho hang 4.
				lcd_putc(dat_line4[i]);		// Lay ky tu hien thi tu chuoi 4 dua len C.LCD.
				}
			}
	  	}
}


my error
Executing: "C:\Program Files\HI-TECH Software\PICC\PRO\9.65\bin\picc.exe" --pass1 C:\Users\giaanthunder\Desktop\keypad\D1.c -q --chip=16F877A -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Error [316] C:\Users\giaanthunder\Desktop\keypad\D1.c; 29.6 "}" expected
Error [316] C:\Users\giaanthunder\Desktop\keypad\D1.c; 29.6 "}" expected
Error [241] C:\Users\giaanthunder\Desktop\keypad\D1.c; 29.6 initialization syntax
Error [316] C:\Users\giaanthunder\Desktop\keypad\D1.c; 37.6 "}" expected
Error [316] C:\Users\giaanthunder\Desktop\keypad\D1.c; 37.6 "}" expected
Error [241] C:\Users\giaanthunder\Desktop\keypad\D1.c; 37.6 initialization syntax
Error [314] C:\Users\giaanthunder\Desktop\keypad\D1.c; 55.1 ";" expected
Error [285] C:\Users\giaanthunder\Desktop\keypad\D1.c; 59.1 no identifier in declaration
Warning [374] C:\Users\giaanthunder\Desktop\keypad\D1.c; 59.1 missing basic type; int assumed
Error [314] C:\Users\giaanthunder\Desktop\keypad\D1.c; 59.1 ";" expected
Error [285] C:\Users\giaanthunder\Desktop\keypad\D1.c; 61.1 no identifier in declaration
Warning [374] C:\Users\giaanthunder\Desktop\keypad\D1.c; 61.1 missing basic type; int assumed
Error [314] C:\Users\giaanthunder\Desktop\keypad\D1.c; 61.1 ";" expected
Error [195] C:\Users\giaanthunder\Desktop\keypad\D1.c; 81.7 expression syntax
Warning [361] C:\Users\giaanthunder\Desktop\keypad\D1.c; 173.5 function declared implicit int
Error [202] C:\Users\giaanthunder\Desktop\keypad\D1.c; 176.17 only lvalues may be assigned to or modified
Error [202] C:\Users\giaanthunder\Desktop\keypad\D1.c; 177.16 only lvalues may be assigned to or modified
Warning [359] C:\Users\giaanthunder\Desktop\keypad\D1.c; 177.16 illegal conversion between pointer types
Error [202] C:\Users\giaanthunder\Desktop\keypad\D1.c; 198.26 only lvalues may be assigned to or modified
Warning [357] C:\Users\giaanthunder\Desktop\keypad\D1.c; 198.26 illegal conversion of integer to pointer
Warning [365] C:\Users\giaanthunder\Desktop\keypad\D1.c; 211.14 pointer to non-static object returned
Warning [358] C:\Users\giaanthunder\Desktop\keypad\D1.c; 211.14 illegal conversion of pointer to integer
Error [202] C:\Users\giaanthunder\Desktop\keypad\D1.c; 243.15 only lvalues may be assigned to or modified
Warning [357] C:\Users\giaanthunder\Desktop\keypad\D1.c; 243.15 illegal conversion of integer to pointer
Error [202] C:\Users\giaanthunder\Desktop\keypad\D1.c; 247.16 only lvalues may be assigned to or modified
Warning [358] C:\Users\giaanthunder\Desktop\keypad\D1.c; 247.16 illegal conversion of pointer to integer


---------- Post added at 01:53 ---------- Previous post was at 01:52 ----------

im using pic 16f877a
 
Last edited by a moderator:

Just glancing at your code.

One issue is you are attempting to load three dimensional data into a two dimensional array:

Original Code:
Code:
const char KEYS[6][8] = {
							{"1","2","3","4","5","6","7","8"},
							{"q","w","e","r","t","y","9","0"},
							{"a","s","d","f","u","i","o","p"},
				 			{"z","x","c","g","h","j","k","l"},
							{"v","b","n","m",",",".","up","enter"},
							{"shift","ctrl"," ","alt","clr","left","down","right"}
							};
const char CAPS[6][8] = {
							{"!","@","#","$","%","^","&","*"}, 		
							{"Q","W","E","R","T","Y","(",")"}, 	
						 	{"A","S","D","F","U","I","O","P"}, 	
						 	{"Z","X","C","G","H","J","K","L"},	
							{"V","B","N","M","<",">","up","enter"},
							{"shift","ctrl"," ","alt","clr","left","down","right"}
							};

Corrected Code:
Code:
const char KEYS[6][8][6] = {
							{"1","2","3","4","5","6","7","8"},
							{"q","w","e","r","t","y","9","0"},
							{"a","s","d","f","u","i","o","p"},
				 			{"z","x","c","g","h","j","k","l"},
							{"v","b","n","m",",",".","up","enter"},
							{"shift","ctrl"," ","alt","clr","left","down","right"}
							};
const char CAPS[6][8][6] = {
							{"!","@","#","$","%","^","&","*"}, 		
							{"Q","W","E","R","T","Y","(",")"}, 	
						 	{"A","S","D","F","U","I","O","P"}, 	
						 	{"Z","X","C","G","H","J","K","L"},	
							{"V","B","N","M","<",">","up","enter"},
							{"shift","ctrl"," ","alt","clr","left","down","right"}
							};


Depending on the routines using these three dimensional arrays, you may want to include a NULL character at the end of each string.

Second issue is you are missing a semicolon from the end of following statement:

Code:
char chuoi_hien_thi[] = "\0"[COLOR="#FF0000"];[/COLOR] //noi dung can hien thi


Third issue is you have not specified the size of the following arrays in either their declarations or definitions:

Code:
	static bit kbd_down = 0; 		// Bien chi thi da co nhan hay chua co nhan phim lan nao (Mac dinh = FALSE).
	[COLOR="#FF0000"]char last_key[]; 		// Bien chua ma phim duoc nhan o lan nhan sau cung (Mac dinh = NULL).[/COLOR]
	unsigned char col = 0;			// Bien thu tu cot duoc quet (Cot tich cuc, mac dinh = cot 0). 
	unsigned char row; 				// Bien thu tu hang co phim nhan (Hang tich cuc).
	[COLOR="#FF0000"]char kchar[]; 			// Bien chua ma phim.[/COLOR]
	unsigned char kbd_call_count; 	// Bien dem so lan goi quet phim de thuc hien chong doi.

	[COLOR="#FF0000"]kchar[] = "\0"; 	// Bien chua ma phim duoc nhan (Mac dinh ban dau chua ky tu NULL).[/COLOR]

You also have not specified the position within the array you wish to store the NULL character, which, by the way, is incorrectly specified as a string literal instead of a single character by using single quotes.

Example:
Code:
kchar[0] = '\0'; 	// Bien chua ma phim duoc nhan (Mac dinh ban dau chua ky tu NULL).


Fix the above issues an post the remaining compiler errors along with the contents of the lcd4x20.h header.


BigDog
 

thanks you so much bigdog. only 4 error in my code

Code:
Error   [195] C:\Users\giaanthunder\Desktop\keypad\D1.c; 185.7 expression syntax
	kchar[] = last_key[];
this instruction wrong or i have to use the function strcpy(k_char,last_key)

Code:
Error   [195] C:\Users\giaanthunder\Desktop\keypad\D1.c; 207.10 expression syntax
	last_key[] = KEYS[row][col];
please help me for bringing a string in the array to last_key[]

Code:
Error   [195] C:\Users\giaanthunder\Desktop\keypad\D1.c; 220.14 expression syntax
	return(kchar[]);
Code:
Error   [195] C:\Users\giaanthunder\Desktop\keypad\D1.c; 252.3 expression syntax
	k[] = kbd_getc();
what wrong with this error ???
 

im having trouble when compiling with mplab 9.65
if you have freetime. can you show me the way you fix these error.
my code
Code:
#include <htc.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include "lcd4x20.h"
#include <string.h>


__CONFIG(HS & WDTDIS & PWRTEN & UNPROTECT & BORDIS & LVPDIS);
#define _XTAL_FREQ 4000000


	#define row0 RA0
	#define row1 RA1
	#define row2 RA2 
	#define row3 RA3 
	#define row4 RA4 
	#define row5 RA5
	#define col0 RB0 
	#define col1 RB1 
	#define col2 RB2 
	#define col3 RB3 
	#define col4 RB4
	#define col5 RB5 
	#define col6 RB6 
	#define col7 RB7

	const char KEYS[6][8] = {
							{"1","2","3","4","5","6","7","8"},
							{"q","w","e","r","t","y","9","0"},
							{"a","s","d","f","u","i","o","p"},
				 			{"z","x","c","g","h","j","k","l"},
							{"v","b","n","m",",",".","up","enter"},
							{"shift","ctrl"," ","alt","clr","left","down","right"}
							};
	const char CAPS[6][8] = {
							{"!","@","#","$","%","^","&","*"}, 		
							{"Q","W","E","R","T","Y","(",")"}, 	
						 	{"A","S","D","F","U","I","O","P"}, 	
						 	{"Z","X","C","G","H","J","K","L"},	
							{"V","B","N","M","<",">","up","enter"},
							{"shift","ctrl"," ","alt","clr","left","down","right"}
							};

	#define kbd_debounce_factor 60

char dat_line1[] = "\0";	// Noi dung can hien thi - Hang 1.
char dat_line2[] = "\0";	// Noi dung can hien thi - Hang 2.
char dat_line3[] = "\0";	// Noi dung can hien thi - Hang 3.
char dat_line4[] = "\0";	// Noi dung can hien thi - Hang 4.

char chuoi_hien_thi[] = "\0" //noi dung can hien thi


bit ALL_ROWS(void)
{						
	if(row0 && row1 && row2 && row3 && row4 && row5) 					
		return(0); 	
	else
		return(1); 	
} 

void kbd_init()
{
ADCON1= 0b00000111;
TRISA= 0xFF;
PORTA= 0xFF;
TRISB= 0x00;
PORTB= 0xFF;
}

char kbd_getc()		// Ham lay ma phim duoc nhan tren ban phim.
{ 
	static bit kbd_down = 0; 		// Bien chi thi da co nhan hay chua co nhan phim lan nao (Mac dinh = FALSE).
	char last_key[]; 		// Bien chua ma phim duoc nhan o lan nhan sau cung (Mac dinh = NULL).
	unsigned char col = 0;			// Bien thu tu cot duoc quet (Cot tich cuc, mac dinh = cot 0). 
	unsigned char row; 				// Bien thu tu hang co phim nhan (Hang tich cuc).
	char kchar[]; 			// Bien chua ma phim.
	unsigned char kbd_call_count; 	// Bien dem so lan goi quet phim de thuc hien chong doi.

	kchar[] = "\0"; 	// Bien chua ma phim duoc nhan (Mac dinh ban dau chua ky tu NULL).
	
	for(kbd_call_count = 0; kbd_call_count <= kbd_debounce_factor; kbd_call_count++) 	// Thuc hien vong lap de chong doi phim nhan.
		{ 
		switch(col)
			{ 
			case 0:
		        col7 = 1; 
		        col6 = 1; 
		        col5 = 1; 
		        col4 = 1;
		        col3 = 1; 
		        col2 = 1; 
		        col1 = 1; 
		        col0 = 0; 
		        break; 
	    	case 1: 
		        col7 = 1; 
		        col6 = 1; 
		        col5 = 1; 
		        col4 = 1; 
		        col3 = 1; 
		        col2 = 1; 
		        col1 = 0; 
		        col0 = 1; 
		        break; 
			case 2:
		        col7 = 1; 
		        col6 = 1; 
		        col5 = 1; 
		        col4 = 1; 
		        col3 = 1; 
		        col2 = 0; 
		        col1 = 1; 
		        col0 = 1; 
		        break; 
			case 3:
		        col7 = 1; 
		        col6 = 1; 
		        col5 = 1; 
		        col4 = 1; 
		        col3 = 0; 
		        col2 = 1; 
		        col1 = 1; 
		        col0 = 1; 
		        break; 
			case 4:
		        col7 = 1; 
		        col6 = 1; 
		        col5 = 1; 
		        col4 = 0;
		        col3 = 1; 
		        col2 = 1; 
		        col1 = 1; 
		        col0 = 1; 
		        break; 
	    	case 5: 
		        col7 = 1; 
		        col6 = 1; 
		        col5 = 0; 
		        col4 = 1; 
		        col3 = 1; 
		        col2 = 1; 
		        col1 = 1; 
		        col0 = 1; 
		        break; 
			case 6:
		        col7 = 1; 
		        col6 = 0; 
		        col5 = 1; 
		        col4 = 1; 
		        col3 = 1; 
		        col2 = 1; 
		        col1 = 1; 
		        col0 = 1; 
		        break; 
			case 7:
		        col7 = 0; 
		        col6 = 1; 
		        col5 = 1; 
		        col4 = 1; 
		        col3 = 1; 
		        col2 = 1; 
		        col1 = 1; 
		        col0 = 1; 
		        break; 
			} 
	
		if(kbd_down) 	// Kiem tra xac nhan viec da co nhan hay chua nhan phim.
						// Neu chua nhan thi kiem tra phim nao se duoc nhan.
						// Neu da co phim nhan thi cho den khi phim da nhan duoc nha (buong ra).
			{ 		// Truong hop da co nhan phim (kbd_down = True) - Cho nha phim da nhan.
			if(!ALL_ROWS()) 	// Neu khong co phim nao duoc nhan (khong con giu phim nhan nua).
				{ 
				kbd_down = 0; 	// Xac nhan khong con phim nao duoc nhan (kbd_down = False). 
				kchar = last_key; 	// Lay ma phim duoc nhan truoc do.
				last_key = "\0"; 		// Cat ma phim (NULL) tuong ung khong nhan phim nao.
	        	} 
			} 
		else 			
			{ 		// Truong hop chua co phim nao nhan (kbd_down = False) - Kiem tra phim nao duoc nhan.
			if(ALL_ROWS()) 		// Neu truong hop CO bat ky phim nao duoc nhan
				{ 				// Kiem tra phim duoc nhan thuoc hang nao (Hang tich cuc).
				if(!row0) 		// Hang 0 tich cuc? (row0 = LOW).
					row = 0; 					// Hang 0.
				else if(!row1) 	// Hang 1 tich cuc? (row1 = LOW).
					row = 1; 					// Hang 1. 
				else if(!row2) 	// Hang 2 tich cuc? (row2 = LOW).
					row = 2;  				// Hang 2.
				else if(!row3) 	// Hang 3 tich cuc? (row3 = LOW).
					row = 3;  				// Hang 3.
				else if(!row4) 	// Hang 1 tich cuc? (row1 = LOW).
					row = 4; 					// Hang 1. 
				else if(!row5) 	// Hang 2 tich cuc? (row2 = LOW).
					row = 5;  				// Hang 2.

	
				last_key = KEYS[row][col]; 	// Lay ma phim dua vao hang (row) va cot (col) tich cuc.
											// Bo ma cua ban phim duoc thiet lap o dau chuong trinh.
				kbd_down = 1; 			// Xac nhan da co phim nhan (kbd_down = True).
				} 
			else 				// Neu truong hop KHONG CO phim nao duoc nhan.
				{ 				// Chuyen sang quet cot ke tiep.
				col++; 		// Tang bien quet cot -> chuyen sang quet cot ke tiep.
				if (col == 8) 	// Xu ly de chi quet 4 cot (tra ve quet cot dau tien).
					col = 0; 	// Cot 0.
				} 
			} 
		} 
	while (ALL_ROWS());	// Cho cho den khi khong con giu phim nua moi tra ve ma phim nhan.
	return(kchar); 	// Tra ve ma ASCII cua phim duoc nhan (bang ma duoc khai bao o dau chuong trinh).
}



void init_PORTC(void)
{
	PORTC = 0X00;
	TRISC = 0X00;
}

void init_PORTD(void)
{
	PORTD = 0X00;
	TRISD = 0X00;
}

void init_PORTE(void)
{
	PORTE = 0X00;
	TRISE = 0X00;
}

void main()
{
	char k[]="\0";

	init_PORTD();
	PORTD = 0x00;
	kbd_init();
	while(1) 	// Vong lap cho ngat.
		{ 
		k = kbd_getc(); 	// Thuc hien quet ban phim va lay ma phim.
		if(k!="\0") 			// Kiem tra co nhan phim (ma phim khac NULL).
			{
			strcpy(chuoi_hien_thi,k);
			kbd_getc()="\0";
			unsigned char i;
			int len=strlen(chuoi_hien_thi);
			if(len<61)
			{
			for(i=0;i<=19;i++)
				dat_line1[i]=chuoi_hien_thi[i];
			for(i=20;i<=39;i++)
				dat_line2[i]=chuoi_hien_thi[i];
			for(i=40;i<=58;i++)
				dat_line3[i]=chuoi_hien_thi[i];
			}
			else
			{
			for(i=len-59;i<=len-38;i++)
				dat_line1[i]=chuoi_hien_thi[i];
			for(i=len-39;i<=len-18;i++)
				dat_line2[i]=chuoi_hien_thi[i];
			for(i=len-19;i<=len-1;i++)
				dat_line3[i]=chuoi_hien_thi[i];			
			}
			lcd_puts("\f");						// Xoa man hinh LCD.
			for(i=0;i<=19;i++)
				{
				lcd_gotoxy(i,0);			// Xac dinh toa do hien thi cho hang 1.
				lcd_putc(dat_line1[i]);		// Lay ky tu hien thi tu chuoi 1 dua len C.LCD.
				lcd_gotoxy(i,1);			// Xac dinh toa do hien thi cho hang 2.
				lcd_putc(dat_line2[i]);		// Lay ky tu hien thi tu chuoi 2 dua len C.LCD.
				lcd_gotoxy(i,2);			// Xac dinh toa do hien thi cho hang 3.
				lcd_putc(dat_line3[i]);		// Lay ky tu hien thi tu chuoi 3 dua len C.LCD.
				lcd_gotoxy(i,3);			// Xac dinh toa do hien thi cho hang 4.
				lcd_putc(dat_line4[i]);		// Lay ky tu hien thi tu chuoi 4 dua len C.LCD.
				}
			}
	  	}
}


my error


---------- Post added at 01:53 ---------- Previous post was at 01:52 ----------

im using pic 16f877a



hello
i try to compile this code using mplab lupic c compiler but it show error. plz i need help. it is very emargency on my study
Plz help me

<><><><><><><><><><>

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <16F877A.H>;                         //declare a PIC header
#device adc=8;                                //set the bit for ADC
#fuses hs, nowdt, noprotect;                    //set the PIC protection
#use delay (clock=20000000);                  //set the clock frequency
int val1;                                    //ADC value 1  left sensor
int val2;                                    //ADC value 2  center sensor
int val3;                                    //ADC value 3  right sensor
int vref;                                    //voltage reference
void lmotor(int gear);                       //left motor function
void rmotor(int gear);                       //right motor function
#byte porta=5;                                //assign port a
#byte portd=8;                                //assign port d
 
void main()                                  //main function
{
   vref=0x7f;                                //set voltage reference value
   set_tris_d(0);                            //declare port d as output
   setup_port_a(all_analog);                 //enable port a as ADC port
   setup_adc(adc_clock_internal);            //set the clock for ADC
   setup_ccp1(ccp_pwm);                      //set enable ccp1
   setup_ccp2(ccp_pwm);                      //set enable ccp2
   setup_timer_2(t2_div_by_4,100,1);         //set post scaler timer
 
   while(1)                                  //inifinite loop
   {
   portd=0xaa;                               //set value for motor
   set_adc_channel(0);                       //ADC at port A0 channel
   val1=read_adc();                          //read and store A0 value
   set_adc_channel(2);                       //ADC at port A2 channel
   val2=read_adc();                          //read and store A2 value
   set_adc_channel(4);                       //Adc at port A4
   val3=read_adc();                          //read and store A4 value
 
   //start condition
   //if sensor sense dark then value is greater than Vref
   //if sensor sense bright then value is lower than Vref
   if(val2>vref)                             //if sensor 2 is dark
   {
      if((val1<vref)&&(val3<vref))           //sensor 1&3 is bright
      {                                      //send value to motor ccp
      lmotor(70);                            //both motor moving at same rate
      rmotor(70);
      }
      else if (val1>vref)                    //sensor 1 is dark
      {
      lmotor(0);                             //left motor stop
      rmotor(70);                            //right motor move
      }
      else if (val3>vref)                    //sensor 3 is dark
      {
      lmotor(70);                            //left motor move
      rmotor(0);                             //right motor stop
      }
   }
   else if ((val1>vref)&&(val3<vref))        //if only sensor 1 is dark
   {
      lmotor(0);                             //left motor stop
      rmotor(70);                            //right motor move
   }
 
 
 
 
 
else if ((val3>vref)&&(val1<vref))               //if only sensor 3 is dark
   {
      lmotor(70);                            //left motor move
      rmotor(0);                             //right motor stop
   }
   else                                      //other than condition above
   {
      lmotor(60);                            //left motor move slow
      rmotor(60);                            //right motor move slow
   }
 
 
   }
}
   //end program
void lmotor(int gear)                        //left motor ccp control function
{
   set_pwm1_duty(gear);                      //ccp1 duty cycle
 
}
 
void rmotor(int gear)                        //right motor ccp control function
{
   set_pwm2_duty(gear);                      //ccp2 duty cycle
}



<><><><><><><><><><><>

If you convert it on the hex file plz give it to me my e-mail is mahedi.siu@gmail.com

thanks
mehedi
 
Last edited by a moderator:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top