# [SOLVED]This project is easy for you but difficult for me

Status
Not open for further replies.

#### mf1364

##### Full Member level 3
This project is easy for you but difficult for me + choosing the best compiler for C

Hi every body
I am new in PIC and C language and I should do this project , so please say that which C commands can help me in this project . and the project is :
I have 10 LEDs and a 4*4 keypad , and if hold the key number 1 for the 1s the first LED should be on for 10s , and if hold the key number 1 for the 2s the second LED should be on for 9s , and this way continue till the 10th LED ... when hold the key number 1 for 10s the 10th LED should be on for 1s and if you hold the key number 1 less than 1s the LEDs should be turn on and off each 0.1s for 10s

beside to solve this project , I want to choose the best PIC compiler for C language so please introduce me your compiler (that have worked with it ) and say why do you think is the best ?and i am using CCS compiler right now so if you have example please give me
Thanks

Last edited:

#### john blue

you have mikroC, C18 and hi tech C to choose from. And everybody has their preference. First, try all the C's and see which suits you.

mf1364

### mf1364

Points: 2

#### andre_teprom

##### Super Moderator
Staff member
The first step to you perform is draw a flowchart describing the working you expect.

+++

mf1364

### mf1364

Points: 2

#### horace1

if you are new to programming PICs you need get some understanding of how to operate the IO pins and use a timer, e.g. setiing TRIS bits and LAT bits etc
1. implement a for() loop blinking a LED on/off
2. read a switch using the on/off value to switch an LED on/off
3. using a timer blink LED on/off 1 second period

you now have the basic knowledge to start implementing the flowchart recommended in previous posts.

mf1364

### mf1364

Points: 2

#### mf1364

##### Full Member level 3
you have mikroC, C18 and hi tech C to choose from. And everybody has their preference. First, try all the C's and see which suits you.

thanks for your reply , but you know I have CCS compiler , can you send for the source of the compiler you said , I want to try them

---------- Post added at 06:49 ---------- Previous post was at 06:44 ----------

The first step to you perform is draw a flowchart describing the working you expect.

+++

can you help me for drawing a flow chart ? i am new in this item too

---------- Post added at 06:53 ---------- Previous post was at 06:49 ----------

if you are new to programming PICs you need get some understanding of how to operate the IO pins and use a timer, e.g. setiing TRIS bits and LAT bits etc
1. implement a for() loop blinking a LED on/off
2. read a switch using the on/off value to switch an LED on/off
3. using a timer blink LED on/off 1 second period

you now have the basic knowledge to start implementing the flowchart recommended in previous posts.

can you write the commands that can read a key from keypad ?

#### horace1

are you using a development board? which microcontroller?

#### mf1364

##### Full Member level 3
are you using a development board? which microcontroller?
What do you mean by development board ? and i am using PIC 16f877A and my compiler is CCS

---------- Post added at 11:05 ---------- Previous post was at 11:01 ----------

#### mf1364

##### Full Member level 3
development boards typically have a range of peripherals and are used to develop prototype systems before designing a PCB for the target project, e.g.
Explorer 16 Development Board
Mechatronics Demonstration Kit
I am so thanks full but there is a problem , the microchip website has filtered in my country so i could not open the links , by the way do you CCS compiler has HELP in its options like other software or not because my version ccs_4.084 does not have!!!! and I want to know its my software problem or this compiler does not have HELP ?!!!!!!!!!

#### horace1

Using the HI-Tech compiler on the Microchip mechatronics board this blinks two LEDs and copies the value of switch to an LED
Code:
// blink two LEDs and copy a switch to LED
//
// connect SW2 ro RA0
// connect RD7, RD6 and RD5 to LEDs

#include <htc.h>

// delay function
void delay(int x)
{
int i;
for(i=0;i<10000;i++);
}

void main(void)
{
while (1){
RP0=1;
TRISA0=1;        	// RA0 is input
TRISD7=0;			// RD7 is output
TRISD6=0;			// RD6 is output
TRISD5=0;			// RD5 is output
ANSEL=0;			// set RA0 digital input
CMCON0=7;			//     "
RP0=0;
RD7=0;				// initialise the LEDs
RD6=1;
RD5=1;
while(1)
{
RD5=RA0;		// copy sw2 to LED
delay(1000);
RD7=!RD7;		// invert LED
RD6=!RD6;		// invert LED
}

}
}

mf1364

### mf1364

Points: 2

#### mf1364

##### Full Member level 3
Using the HI-Tech compiler on the Microchip mechatronics board this blinks two LEDs and copies the value of switch to an LED
thank you so much , can you explain more about pros and cons of HI-tech ? and compare it with CCS and micro C compilers ? because i am at the begin of the way and i am looking forwards to finding the best compiler for the C language and PIC microcontroller

mf1364

### mf1364

Points: 2

#### mf1364

##### Full Member level 3
Does any body know , what is the formula for build real time ? because i can turn on and turn off LEDs with push-button but now I want to control lighting Time and build times 1s ,2s,....10s and as I said before I use CCS , and C language.

---------- Post added at 11:24 ---------- Previous post was at 11:23 ----------

cannot help with advice as I have not used the PIC16 for many years and then I only used the Hi-Tech compiler

Thank you very much , I want to instull a Hi-Tech compiler but , that Has some internal problem so can you introduce a free link ?

#### horace1

cannot help with advice as I have not used the PIC16 for many years and then I only used the Hi-Tech compiler

Thank you very much , I want to instull a Hi-Tech compiler but , that Has some internal problem so can you introduce a free link ?
HI-TECH C for the PIC10/12/16 MCU Family

mf1364

### mf1364

Points: 2

#### mf1364

##### Full Member level 3
I have problem with making time , because as i mentioned in this project I need These times , 1s,2s ... 10s but the problem is I dont know how should I use the Timer/Counter to making these times , please help me

#### mf1364

##### Full Member level 3
finally I did it , i did it :-D and here is my codes but i should mention that i use LCD and instead of 10 LEDs i just one LED by the way i used micro C compiler instead of CCS
//// this project adjust the lighting ON and OFF the LED according by
////the holding time of key 1 a 4*4 key pad
////////////////Define variants////////////////////
unsigned short kp;
unsigned char txt[1];
unsigned char txt1[1];
unsigned short kp1;
unsigned short count;
/////////////This Function showes numbers on the LCD and according the time of
////////////holding the key 1 turn on and turn off the LED
void LCDshow(){
if (kp==1) count++;
WordToStr(kp, txt);
Lcd_out(1, 10,txt);
WordToStr(count, txt1);
Lcd_out(2, 10,txt1);
delay_ms(500);
Lcd_Cmd(LCD_CLEAR);
if (kp!=1) {
if(count==2) {portc.f0=1;delay_ms(10000);portc.f0=0;}
if(count==4) {portc.f0=1;delay_ms(9000);portc.f0=0;}
if(count==6) {portc.f0=1;delay_ms(8000);portc.f0=0;}
if(count==8) {portc.f0=1;delay_ms(7000);portc.f0=0;}
if(count==10) {portc.f0=1;delay_ms(6000);portc.f0=0;}
if(count==12) {portc.f0=1;delay_ms(5000);portc.f0=0;}
if(count==14) {portc.f0=1;delay_ms(4000);portc.f0=0;}
if(count==16) {portc.f0=1;delay_ms(3000);portc.f0=0;}
if(count==18) {portc.f0=1;delay_ms(2000);portc.f0=0;}
if(count==20) {portc.f0=1;delay_ms(1000);portc.f0=0;}
count=0;
}
}
/////////////Main Function/////////////////////////////////////////
void main() {
// portc.f0=0;
trisc.f0 =0;
Lcd_Config(&PORTc,1,2,0,7,5,4,3); // Initialize LCD on PORTC
Lcd_Cmd(LCD_CLEAR); // Clear display
Lcd_Cmd(LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1, 1, "Key :");
while(1){
LCDshow();
}
}

#### mf1364

##### Full Member level 3
now I want to make real time with timers . dose any body can help me ?

#### dv_sa559

Hi
if you need high precision rtc you need to use rct ic such as DS1307 .

mf1364

### mf1364

Points: 2

#### mf1364

##### Full Member level 3
no buddy , i want to use timers just for learning how to use them because i am so new in pic by the way i am using pic16873A and miKroC compiler . i am hardly looking forward to finding a pdf for learning how to use timer/counter especially for pic16873A

Status
Not open for further replies.

Replies
3
Views
935
Replies
0
Views
1K
Replies
0
Views
711
Replies
1
Views
1K
Replies
0
Views
2K