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.

PIC 16F877A clock alarm project need to add a variable text during the buzz !

Status
Not open for further replies.

yasser-killua

Newbie level 4
Newbie level 4
Joined
Feb 2, 2013
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,398
Hello!
i want to build a project wich i can add time alarm + text
and when the alarm will turn on i mean :
if((alarm_hour == hours) && (alarm_min == mins )) // If it is alarm time,
a small text will appear in the LCD wich i already written it such a variable
i have the project of the alarm clock with the code in mikroC and also the programme of keypad+lcd
codes (mikroc):
alarm:
// Global date/time variables
char sec, mins, hours, date, day, month, year;
char day_name[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
char alarm_hour=0, alarm_min=0;
const char character1[] = {0,4,14,14,31,31,4,0}; // Bell's LCD code
const char character2[] = {31,27,17,17,0,0,27,31}; // Bell's Invert LCD code
////////////////////////////////////////////////////////////////



// LCD module connections
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections


// Custom character function
void CustomChar(char pos_row, char pos_char, char num)
{
Lcd_Chr(pos_row, pos_char, num);
}


void fixed_text()
{
// Lcd_Out(1,1,"Date:");
Lcd_Chr(1,5,'-');
Lcd_Chr(1,8,'-');
//Lcd_Out(2,1,"Time:");
Lcd_Chr(2,5,':');
Lcd_Chr(2,8,':');
Lcd_Out(1,9,"20");
}

void conversion()// Convert BCD to DEC
{
sec = ((sec & 0xF0) >> 4)*10 + (sec & 0x0F); // Transform seconds
mins = ((mins & 0xF0) >> 4)*10 + (mins & 0x0F); // Transform months
hours = ((hours & 0xF0) >> 4)*10 + (hours & 0x0F); // Transform hours
year = ((year & 0xF0) >> 4)*10 + (year & 0x0F); // Transform hours
date = ((date & 0xF0) >> 4)*10 + (date & 0x0F); // Transform day
month = ((month & 0xF0) >> 4)*10 + (month & 0x0F); // Transform month
}

void display_date()
{
Lcd_Chr(1, 3, (date / 10) + 48); // Print tens digit of day variable
Lcd_Chr(1, 4, (date % 10) + 48); // Print oness digit of day variable
}

void display_month()
{
Lcd_Chr(1, 6, (month / 10) + 48);
Lcd_Chr(1, 7, (month % 10) + 48);
}

void display_year()
{
Lcd_Chr(1, 11,(year / 10) + 48);
Lcd_Chr(1, 12, (year % 10) + 48);
}

void display_hours()
{
Lcd_Chr(2, 3, (hours / 10) + 48);
Lcd_Chr(2, 4, (hours % 10) + 48);
}

void display_alarmHour()
{
Lcd_Chr(2, 6, (alarm_hour / 10) + 48);
Lcd_Chr(2, 7, (alarm_hour % 10) + 48);
}

void display_alarmMin()
{
Lcd_Chr(2, 9, (alarm_min / 10) + 48);
Lcd_Chr(2, 10,(alarm_min % 10) + 48);
}

void display_minutes()
{
Lcd_Chr(2, 6, (mins / 10) + 48);
Lcd_Chr(2, 7, (mins % 10) + 48);
}

void display_seconds()
{
Lcd_Chr(2, 9, (sec / 10) + 48);
Lcd_Chr(2,10, (sec % 10) + 48);
}

void display_day()
{
if(day == 0)
{
day = 1;
}
Lcd_Out(2,13, (day_name [day-1]));
}

void main()
{
////////////////////////////////////////////////////////////
char count = 0, i = 0, j = 0, alarmSet=0;

//TRISB |= 0b00000100;
TRISB = 0b00000011;
PORTB=0;

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

// Store custome characters//
Lcd_Cmd(64);
for (i = 0; i<=7; i++)
{
Lcd_Chr_CP(character1);
}
Lcd_Cmd(72);
for (i = 0; i<=7; i++)
{
Lcd_Chr_CP(character2);
}
///////////////////////////////////////////


I2C1_Init(100000); // Initialize Soft I2C communication

while (1) // Endless loop
{
///////////////////////////////////////////////////////////////////
while(count == 0) // This Loop show the time
{
fixed_text();

I2C1_Start(); // Issue start signal
I2C1_Wr(0xD0); // Address DS1307, W=0
I2C1_Wr(0); // Start from address 0
I2C1_Repeated_Start(); // Issue repeated start signal
I2C1_Wr(0xD1); // Address DS1307, R=1

sec = I2C1_Rd(1); // Read seconds byte
mins = I2C1_Rd(1); // Read minutes byte
hours = I2C1_Rd(1); // Read hours byte
day = I2C1_Rd(1); // Read day byte
date = I2C1_Rd(1); // Read date byte
month = I2C1_Rd(1); // Read month byte
year = I2C1_Rd(0); // Read year byte
I2C1_Stop(); // Issue stop signal

conversion(); // Convert BCD to DEC

display_date(); // Show time in LCD
display_month();
display_year();
display_hours();
display_minutes();
display_seconds();
display_day();

Delay_ms(500);

if(alarmSet == 1) // If alarm is set then show the "Bell" sign
{
CustomChar(1,14,0);
if((alarm_hour == hours) && (alarm_min == mins )) // If it is alarm time,
{ // then ring the bell.
alarmSet = 2;
RB2_bit = 1;//SOUNDER
i=0;
Lcd_Cmd(_LCD_CLEAR); // Clear LCD display
Lcd_Out(1,3, "MA");
}
}

else if(alarmSet == 2) // Animation of the "Bell"
{
j = ++j % 2;
CustomChar(1,14,j);
}

if(RB0_bit == 1) //Menu / Next / Alarm Off
{
if(alarmSet == 2) // If alarm ringing, then off the alarm
{
alarmSet = 0;
RB2_bit = 0;//SOUNDER
Lcd_Chr(1,14,' ');
}
else
// Go to the "Menu"
{
count = 1;
Lcd_Cmd(_LCD_CLEAR); // Clear LCD display
Lcd_Out(1,3, "Date & Time >");
while(RB0_bit);//Menu / Next / Alarm Off
}
}
}
////////////////////////////////////////////////////////////////////////////////

while(count == 1)
{
if(RB1_bit == 1) //Increase / Select Menu
{
while(RB1_bit);
Lcd_Cmd(_LCD_CLEAR);
fixed_text();
display_date();
display_month();
display_year();
display_hours();
display_minutes();
display_seconds();
display_day();
Lcd_Cmd(_LCD_MOVE_CURSOR_LEFT);
Lcd_Cmd(_LCD_BLINK_CURSOR_ON);
count = 2;
}
else if(RB0_bit == 1)
{
count = 9;
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1, "< Alarm Time");
while(RB0_bit);
}
}

///////////
while(count == 2)
{
if(RB1_bit == 1)
{
day++;
if(day > 7)
{
day = 1;
}
display_day();
Lcd_Cmd(_LCD_MOVE_CURSOR_LEFT);
while(RB1_bit == 1);
}
else if(RB0_bit == 1)
{
count = 3;
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_FIRST_ROW);
for(i = 0; i <= 13; i++)
{
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
}
Lcd_Cmd(_LCD_BLINK_CURSOR_ON);
while(RB0_bit);
}
}
while(count == 3)
{
if(RB1_bit)
{
year++;
if(year > 99)
{
year = 0;
}
display_year();
Lcd_Cmd(_LCD_MOVE_CURSOR_LEFT);
while(RB1_bit);
}
else if(RB0_bit)
{
count = 4;
for(i = 0; i <= 4; i++)
{
Lcd_Cmd(_LCD_MOVE_CURSOR_LEFT);
}
while(RB0_bit);
}
}
while(count == 4)
{
if(RB1_bit)
{
month++;
if(month > 12)
{
month = 1;
}
display_month();
Lcd_Cmd(_LCD_MOVE_CURSOR_LEFT);
while(RB1_bit);
}
else if(RB0_bit == 1)
{
count = 5;
for(i = 0; i <= 2; i++)
{
Lcd_Cmd(_LCD_MOVE_CURSOR_LEFT);
}
while(RB0_bit);
}
}
while(count == 5)
{
if(RB1_bit == 1)
{
date++;
if(date > 31)
{
date = 0;
}
display_date();
Lcd_Cmd(_LCD_MOVE_CURSOR_LEFT);
while(RB1_bit);
}
else if(RB0_bit == 1)
{
count = 6;
Lcd_Cmd(_LCD_SECOND_ROW);
for(i = 0; i <= 5; i++)
{
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
}
while(RB0_bit);
}
}
while(count == 6)
{
if(RB1_bit)
{
hours++;
if(hours > 23)
{
hours = 0;
}

display_hours();
Lcd_Cmd(_LCD_MOVE_CURSOR_LEFT);
while(RB1_bit);
}
else if(RB0_bit)
{
count = 7;
for(i = 0; i <= 2; i++)
{
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
}
while(RB0_bit);
}
}
while(count == 7)
{
if(RB1_bit)
{
mins++;
if(mins > 59)
{
mins = 0;
}

display_minutes();
Lcd_Cmd(_LCD_MOVE_CURSOR_LEFT);
while(RB1_bit);
}
else if(RB0_bit)
{
count = 8;

for(i = 0; i <= 2; i++)
{
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
}
while(RB0_bit);
}
}
while(count == 8)
{
if(RB1_bit)
{
sec++;
if(sec > 59)
{
sec = 0;
}
display_seconds();
Lcd_Cmd(_LCD_MOVE_CURSOR_LEFT);
while(RB1_bit);
}
else if(RB0_bit)
{
I2C1_Start(); // Issue start signal
I2C1_Wr(0xD0);
I2C1_Wr(0); // Start from address 0

I2C1_Wr(Dec2Bcd(sec)); // Write seconds byte
I2C1_Wr(Dec2Bcd(mins)); // Write minutes byte
I2C1_Wr(Dec2Bcd(hours));// Write hours byte
I2C1_Wr(Dec2Bcd(day)); // Write day byte
I2C1_Wr(Dec2Bcd(date)); // Write date byte
I2C1_Wr(Dec2Bcd(month));// Write month byte
I2C1_Wr(Dec2Bcd(year)); // Write year byte
I2C1_Stop(); // Issue stop signal

count = 0;
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_CLEAR); // Clear LCD display
Lcd_Out(1,1,"Time & Date Set"); // Prepare and output static text on LCD
Delay_ms(1000);
while(RB0_bit);
}
}
while(count == 9)
{
if(RB0_bit == 1)
{
count = 0;
Lcd_Cmd(_LCD_CLEAR); // Clear LCD display
while(RB0_bit);
}
else if(RB1_bit == 1)
{
count = 10;

Lcd_Cmd(_LCD_CLEAR); // Clear LCD display
Lcd_Out(1,4,"Set Alarm"); // Prepare and output static text on LCD
Lcd_Out(2,8,":"); // Prepare and output static text on LCD
display_alarmHour();
display_alarmMin();
for(i = 0; i <= 3; i++)
{
Lcd_Cmd(_LCD_MOVE_CURSOR_LEFT);
}
Lcd_Cmd(_LCD_BLINK_CURSOR_ON);
while(RB1_bit);
}
}
while(count == 10)
{
if(RB1_bit == 1)
{
alarm_hour++;
if(alarm_hour > 23)
{
alarm_hour = 0;
}
Delay_ms(300);
display_alarmHour();
Lcd_Cmd(_LCD_MOVE_CURSOR_LEFT);
}
else if(RB0_bit == 1)
{
count = 11;
for(i = 0; i <= 2; i++)
{
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
}
while(RB0_bit);
}
}
while(count == 11)
{
if(RB1_bit == 1)
{
alarm_min++;
if(alarm_min > 59)
{
alarm_min = 0;
}
Delay_ms(300);
display_alarmMin();
Lcd_Cmd(_LCD_MOVE_CURSOR_LEFT);
}
else if(RB0_bit)
{
count = 0;
alarmSet = 1;
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,4,"Alarm Set"); // Prepare and output static text on LCD
Delay_ms(1000);
while(RB0_bit);
}
}
}
}

keypad :
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;

char keypadPort at PORTD;

char mm;
void main() {
Lcd_Init();
Keypad_Init();
Lcd_Cmd(_LCD_CLEAR);Lcd_Cmd(_LCD_CURSOR_OFF);

Lcd_Out(2, 5, "((mm))");

while(1){
mm=0;
while(!mm){mm = Keypad_Key_Click();}

switch (mm) {

case 1: mm = 55; break; // 1
case 2: mm = 56; break; // 2
case 3: mm = 57; break; // 3
case 4: mm = 65; break; // A
case 5: mm = 52; break; // 4
case 6: mm = 53; break; // 5
case 7: mm = 54; break; // 6
case 8: mm = 66; break; // B
case 9: mm = 49; break; // 7
case 10: mm = 50; break; // 8
case 11: mm = 51; break; // 9
case 12: mm = 67; break; // C
case 13: mm = 42; break; // *
case 14: mm = 48; break; // 0
case 15: mm = 35; break; // #
case 16: mm = 68; break; // D

}

Lcd_Chr(1, 7, mm);
}

}

all i want is :
1) collecting the two projects in one
2) realise this commande :

if((alarm_hour == hours) && (alarm_min == mins )) // If it is alarm time,
{ // then ring the bell and display text
alarmSet = 2;
RB2_bit = 1;//SOUNDER
Lcd_Out(2, 5, "((mm))"); // mm is a variable include the text


3) use the same LCD for the communication and displaying

so i need to add the keypad in alarm project

please need your help :-(
Thank you !
 

Attachments

  • alarm.PNG
    alarm.PNG
    29.2 KB · Views: 90
  • keypad.PNG
    keypad.PNG
    29.4 KB · Views: 84

The code is difficult to read because the forum software only accepts plain text. It removes the tabs and leading spaces so your program is difficult to read. Go back to your first post and click EDIT then either highlight the code and click the code tag icon '#' or type '[ CODE ]' before it and '[ / CODE ]' after it with the spaces removed.

Anyway, you almost did the work yourself. Use the code you suggested and add your text in the same way as the "void fixed_text()" example shows. You will have a small problem because when you only check the alarm hour and minute match the time, it will be true for the whole minute so your text may be repeated many times. The cure is to add a variable, something like "AlarmIsTriggered" which you set after the text is displayed and reset when the minute has changed. You only display the text if the variable is not set, this makes it show only once.

Brian.
 

how can i write two charachters in the keypad and save theme as a variables , it happened just with only one charachter
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top