Need Help in mikroc 8.2

Status
Not open for further replies.

aneeshere

Junior Member level 1
Joined
Jun 21, 2010
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
india
Activity points
1,436
friends,

I am new to pic and mikroc compiler. I am trying to make a digital clock using DS1307 and 16f877a and lcd.

ive written a code in c for the compiler mikroC.

ive used pins RD0,RD1,RD2,RD3 for buttons of the clock and also ive used library functions for lcd.
when i tried to build it it shows error as follows

undeclared identifier [RD0]
')' expected but ';' found
Internal error

experts out there please help me.its no syntax error.
 

Check how pins are accessed in that compiler.
--
Amr
 

from the manual of the compiler.
Mikro C is well documented and has many examples.
Search for I/O ports.
--
Amr
 

    aneeshere

    Points: 2
    Helpful Answer Positive Rating
so ill have to download the manual from internet?
thanks. ill check it out
 

Yes download the manual. you will find some programming examples with circuit connections.
--
Amr
 

if i give you my code can you please sort it out for me?
 

Hi,
From the error, I can tell that somewhere in the code you have used either RD0 or [RD0]. Instead use PORTD.B0, PORTD.B1 and so on.

Hope this helps.
Tahmid.
 

yea exactly. I used RD0,RD1,RD2,RD3 since it showed error i went for PORTD.F0 to PORTD.F3
is PORTD.B0 the correct usage?
 

Hi,
I think so. I use mikroBASIC, where I use PORTD.B0
I know that for mikroC, PORTD.F0 is correct.

Hope this helps.
Tahmid.
 

I avoided using RD0 to RD4.

instead i thought of checking
if(PORTD==0X01) instead of if(RD0==1)
and
if(PORTD==0X02) in place of (RD1=1)

initially i did TRISD=0x0F; and PORTD=0;

i generated the hex but is this method correct logically?
 

Hi,
Problem is, if, say you pressed both RD0 and RD1 switches, be it deliberately or accidentally. Then, PORTD.B0 and PORTD.B1 will both read true, but neither PORTD=1 nor PORTD=2 will read true.

I hope I made myself clear.

Hope this helps.
Tahmid.
 

    aneeshere

    Points: 2
    Helpful Answer Positive Rating
yea i did think of it.that is a limitation maybe.
there are four if statement to check pressing of RD0 RD1 RD2 and RD3.so the values to be compared are PORT==0X01,0X02,0X04 and 0X08 respectively. and once in the if the fisrt statement is PORTD=0 for each if

Added after 1 minutes:

These buttons connected to RD0 to RD3 are for setting time in the clock.so the user is
not supposed to press two at a time.
 

instead of
Code:
if(PORTD==0X01) instead of if(RD0==1) 
and 
if(PORTD==0X02) in place of (RD1=1) 

initially i did TRISD=0x0F; and PORTD=0;

make it
Code:
if(PORTD & 0X01) instead of if(RD0==1) 
and 
if(PORTD & 0X02) in place of (RD1=1) 

initially  TRISD=0x0F; and PORTD=0;
so even if you press both buttons, the logic will be true...

(PORTD & 0x02) is just ((PORTD & 0x2)!=0) so when RD2 is 1 the condition will be true, when RD2 is 0 the condition will be false... discarding the other PORTD bits....
 

    aneeshere

    Points: 2
    Helpful Answer Positive Rating
U meant RD1 instead of RD2 right?

and for RD2 it will be if(PORTD & 0X04)
am i right?
 

oh yes, my mistake!

for RD0 the condition is (PORTD & 0x01)
for RD1 the condition is (PORTD & 0x02)
for RD2 the condition is (PORTD & 0x04)
for RD3 the condition is (PORTD & 0x08)

and so on until 128 for bit 7

i'm not sure if mikroC likes the preporcening but maybe you can define the ol' "bitvalue" macro...

Code:
#define bVal(b) (1<<(b))

...

//and then use it like this:
(PORTD & bVal(0)) //for bit0
(PORTD & bVal(1)) //for bit1
(PORTD & bVal(2)) //for bit2
(PORTD & bVal(3)) //for bit3

so you will not commit my silly mistake...
 

the thing is i used if(portd==0x01) etc and compiled and created hex.
for time being leave aside the trouble of two buttons at a time and i tried simulating using proteus. but when i pressed the button corresponding to RD0 the lcd should diplay "Set Hour" but nothing happens.

does that mean that portd is not changing according to my pressing of buttons?
 

* Test configuration:
MCU: PIC16F887
Dev.Board: Breadboard
Oscillator: HS, 8.0000 MHz
Ext. Modules: -
SW: mikroC Pro v4.60

*/


unsigned char sec, min1, hr, week_day, day, mn, year;
char *txt, tnum[4];

// Software I2C connections
sbit Soft_I2C_Scl at RC3_bit;
sbit Soft_I2C_Sda at RC4_bit;
sbit Soft_I2C_Scl_Direction at TRISC3_bit;
sbit Soft_I2C_Sda_Direction at TRISC4_bit;


// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

void Zero_Fill(char *value) { // fill text repesentation
if (value[1] == 0) { // with leading zero
value[1] = value[0];
value[0] = 48;
value[2] = 0;
}
}//~

//--------------------- Reads time and date information from RTC (DS1307)
void Read_Time(char *sec, char *min, char *hr, char *week_day, char *day, char *mn, char *year) {
I2C1_Start();
I2C1_Wr(0xD0);
I2C1_Wr(0);
I2C1_Repeated_Start();
I2C1_Wr(0xD1);
*sec =I2C1_Rd(1);
*min =I2C1_Rd(1);
*hr =I2C1_Rd(1);
*week_day =I2C1_Rd(1);
*day =I2C1_Rd(1);
*mn =I2C1_Rd(1);
*year =I2C1_Rd(0);
I2C1_Stop();
}//~

//-------------------- Formats date and time
void Transform_Time(char *sec, char *min, char *hr, char *week_day, char *day, char *mn, char *year) {
*sec = ((*sec & 0x70) >> 4)*10 + (*sec & 0x0F);
*min = ((*min & 0xF0) >> 4)*10 + (*min & 0x0F);
*hr = ((*hr & 0x30) >> 4)*10 + (*hr & 0x0F);
*week_day =(*week_day & 0x07);
*day = ((*day & 0xF0) >> 4)*10 + (*day & 0x0F);
*mn = ((*mn & 0x10) >> 4)*10 + (*mn & 0x0F);
*year = ((*year & 0xF0)>>4)*10+(*year & 0x0F);
}//~

//-------------------- Output values to LCD
void Display_Time(char sec, char min, char hr, char week_day, char day, char mn, char year) {
switch(week_day){
case 1: txt="Sun"; break;
case 2: txt="Mon"; break;
case 3: txt="Tue"; break;
case 4: txt="Wed"; break;
case 5: txt="Thu"; break;
case 6: txt="Fri"; break;
case 7: txt="Sat"; break;
}
LCD_Out(1,1,txt);
Lcd_Chr(1, 6, (day / 10) + 48); // Print tens digit of day variable
Lcd_Chr(1, 7, (day % 10) + 48); // Print oness digit of day variable
Lcd_Chr(1, 9, (mn / 10) + 48);
Lcd_Chr(1,10, (mn % 10) + 48);
Lcd_Chr(1,15, year + 48); // Print year vaiable + 8 (start from year 2008)

Lcd_Chr(2, 6, (hr / 10) + 48);
Lcd_Chr(2, 7, (hr % 10) + 48);
Lcd_Chr(2, 9, (min / 10) + 48);
Lcd_Chr(2,10, (min % 10) + 48);
Lcd_Chr(2,12, (sec / 10) + 48);
Lcd_Chr(2,13, (sec % 10) + 48);

}//~

//------------------ Performs project-wide init
void Init_Main() {
ANSEL=0;
ANSELH=0;

Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear LCD display
Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off

I2C1_Init(100000); // initialize I2C
LCD_Chr(1,8,'.');
LCD_Chr(1,11,'.');
txt = "Time:";
LCD_Out(2,1,txt);
LCD_Chr(2,8,':');
LCD_Chr(2,11,':');
txt = "201";
LCD_Out(1,12,txt);
LCD_Cmd(_LCD_CURSOR_OFF);
}//~

//----------------- Main procedure
void main() {
Init_Main(); // perform initialization
while (1) {
Read_Time(&sec,&min1,&hr,&week_day,&day,&mn,&year); // read time from RTC(DS1307)
Transform_Time(&sec,&min1,&hr,&week_day,&day,&mn,&year); // format date and time
Display_Time(sec, min1, hr, week_day, day, mn, year); // prepare and display on LCD
Delay_ms(1000); // wait 1s
}
}//


This code will work only mikroC pro. Plz, download new mikroc pro.

---------- Post added at 03:31 ---------- Previous post was at 03:30 ----------

* Test configuration:
MCU: PIC16F877A
Dev.Board: Breadboard
Oscillator: HS, 8.0000 MHz
Ext. Modules: -
SW: mikroC Pro v4.60

*/


unsigned char sec, min1, hr, week_day, day, mn, year;
char *txt, tnum[4];

// Software I2C connections
sbit Soft_I2C_Scl at RC3_bit;
sbit Soft_I2C_Sda at RC4_bit;
sbit Soft_I2C_Scl_Direction at TRISC3_bit;
sbit Soft_I2C_Sda_Direction at TRISC4_bit;


// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

void Zero_Fill(char *value) { // fill text repesentation
if (value[1] == 0) { // with leading zero
value[1] = value[0];
value[0] = 48;
value[2] = 0;
}
}//~

//--------------------- Reads time and date information from RTC (DS1307)
void Read_Time(char *sec, char *min, char *hr, char *week_day, char *day, char *mn, char *year) {
I2C1_Start();
I2C1_Wr(0xD0);
I2C1_Wr(0);
I2C1_Repeated_Start();
I2C1_Wr(0xD1);
*sec =I2C1_Rd(1);
*min =I2C1_Rd(1);
*hr =I2C1_Rd(1);
*week_day =I2C1_Rd(1);
*day =I2C1_Rd(1);
*mn =I2C1_Rd(1);
*year =I2C1_Rd(0);
I2C1_Stop();
}//~

//-------------------- Formats date and time
void Transform_Time(char *sec, char *min, char *hr, char *week_day, char *day, char *mn, char *year) {
*sec = ((*sec & 0x70) >> 4)*10 + (*sec & 0x0F);
*min = ((*min & 0xF0) >> 4)*10 + (*min & 0x0F);
*hr = ((*hr & 0x30) >> 4)*10 + (*hr & 0x0F);
*week_day =(*week_day & 0x07);
*day = ((*day & 0xF0) >> 4)*10 + (*day & 0x0F);
*mn = ((*mn & 0x10) >> 4)*10 + (*mn & 0x0F);
*year = ((*year & 0xF0)>>4)*10+(*year & 0x0F);
}//~

//-------------------- Output values to LCD
void Display_Time(char sec, char min, char hr, char week_day, char day, char mn, char year) {
switch(week_day){
case 1: txt="Sun"; break;
case 2: txt="Mon"; break;
case 3: txt="Tue"; break;
case 4: txt="Wed"; break;
case 5: txt="Thu"; break;
case 6: txt="Fri"; break;
case 7: txt="Sat"; break;
}
LCD_Out(1,1,txt);
Lcd_Chr(1, 6, (day / 10) + 48); // Print tens digit of day variable
Lcd_Chr(1, 7, (day % 10) + 48); // Print oness digit of day variable
Lcd_Chr(1, 9, (mn / 10) + 48);
Lcd_Chr(1,10, (mn % 10) + 48);
Lcd_Chr(1,15, year + 48); // Print year vaiable + 8 (start from year 2008)

Lcd_Chr(2, 6, (hr / 10) + 48);
Lcd_Chr(2, 7, (hr % 10) + 48);
Lcd_Chr(2, 9, (min / 10) + 48);
Lcd_Chr(2,10, (min % 10) + 48);
Lcd_Chr(2,12, (sec / 10) + 48);
Lcd_Chr(2,13, (sec % 10) + 48);

}//~

//------------------ Performs project-wide init
void Init_Main() {
ANSEL=0;
ANSELH=0;

Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear LCD display
Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off

I2C1_Init(100000); // initialize I2C
LCD_Chr(1,8,'.');
LCD_Chr(1,11,'.');
txt = "Time:";
LCD_Out(2,1,txt);
LCD_Chr(2,8,':');
LCD_Chr(2,11,':');
txt = "201";
LCD_Out(1,12,txt);
LCD_Cmd(_LCD_CURSOR_OFF);
}//~

//----------------- Main procedure
void main() {
Init_Main(); // perform initialization
while (1) {
Read_Time(&sec,&min1,&hr,&week_day,&day,&mn,&year); // read time from RTC(DS1307)
Transform_Time(&sec,&min1,&hr,&week_day,&day,&mn,&year); // format date and time
Display_Time(sec, min1, hr, week_day, day, mn, year); // prepare and display on LCD
Delay_ms(1000); // wait 1s
}
}//


This code will work only mikroC pro. Plz, download new mikroc pro.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…