I keep getting "error: (1089) recursive function call to "_Screen" " and I dont know why?
The progrm worked when I had the "show_menu()" function as the main routine but I want the "Screen()" first but I need it callable from the menu array.
The progrm worked when I had the "show_menu()" function as the main routine but I want the "Screen()" first but I need it callable from the menu array.
C:
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include "Menu_Stuct.h"
#include "lcd.h"
#include "lcd_extra.h"
#include "i2c.h"
// **************** DEFINES *************************************************
// MENU
#define ENTER PORTAbits.RA1 ;
#define UP PORTAbits.RA2 ;
#define DOWN PORTAbits.RA3 ;
// I2C
#define MSB(x) ((x>>4)+ '0') //Display Most Significant Bit of BCD number
#define LSB(x) ((x & 0x0F) + '0') //Display Least Significant Bit of BCD number
#define I2C_SCL TRISCbits.TRISC3
#define I2C_SDA TRISCbits.TRISC4
// ******************* Global Variables *************************************
// I2C
unsigned short read_ds1307(unsigned short addressReg); //Function to read from the DS1307
void write_ds1307(unsigned short addressReg, unsigned short w_dataReg); //Function to write to the DS1307
char Binary2BCD(char aa); //Convert Binary to BCD
char BCD2Binary(char aa); //Convert BCD to Binary
char time[] = "00:00:00";
char ON_Blue[] = "00:00";
char OFF_Blue[] = "00:00";
char ON_Main[] = "00:00";
char OFF_Main[] = "00:00";
char second;
char minute;
char hour;
char hr;
char ON_Blue_Hour = 0b00010000;
char ON_Blue_Minute = 0b01000101;
char OFF_Blue_Hour = 0b00100000;
char OFF_Blue_Minute = 0b0011000;
char ON_Main_Hour;
char ON_Main_Minute;
char OFF_Main_Hour;
char OFF_Main_Minute;
char temp_hour;
char temp_minute;
unsigned short set_count = 0;
short set;
char absolute(char a);
// MENU
unsigned char line_cnt = 0;
unsigned char from = 0;
unsigned char till = 0;
unsigned char temp = 0;
unsigned char button;
unsigned char selected = 1;
typedef const struct MenuStructure {
const char *text;
unsigned char up;
unsigned char down;
unsigned char enter;
void ( *fp) (void);
} MenuEntry;
/*
*
*/
const char menu_000[] = " MAIN Zero "; //0
const char menu_001[] = " Set Time"; // 1
const char menu_002[] = " Lights"; // 2
const char menu_003[] = " Dosage"; // 3
const char menu_004[] = " Done"; // 4
const char menu_100[] = " SUB Zero "; //5
const char menu_101[] = " On/Off"; // 6 Light Sub Menu
const char menu_102[] = " Colour"; // 7 Time On/Off
const char menu_103[] = " Fade"; // 8 RGB Settings
const char menu_104[] = " Done"; // 9 Fade up
/* array discription
----------------------------------- menu name
|
| |---------------------- If Up pressed goto
| | |------------------ If Down pressed goto
| | | |-------------- If Enter Pressed goto
| | | | |---------- Function on enter
*/
MenuEntry menu[] = {
{menu_000, 0, 0, 0, 0}, //0
{menu_001, 1, 2, 1, Set_Time}, //1
{menu_002, 1, 3, 5, 0}, //2 // Goto lights 6
{menu_003, 2, 4, 3, 0}, //3
{menu_004, 3, 4, 4, Screen}, //4
{menu_101, 5, 6, 5, Lights_ON_OFF}, //5
{menu_102, 5, 7, 6, Lights_Colour}, //6
{menu_103, 6, 8, 7, Lights_Fade}, //7
{menu_104, 7, 8, 1, 0}, //8
};
//************* MAIN *******************************************************
void main(void) {
ADCON1 = 0x0F; // No analog, all digital i/o
TRISA = 0b00001110;
LATA = 0b00001110;
TRISB = 0x00;
TRISC = 0x00;
TRISG = 0x00;
LATB = 0x00;
LATG = 0x00;
OpenXLCD(FOUR_BIT & LINES_5X7); // Start LCD
WriteCmdXLCD(CURSOR_OFF & BLINK_OFF);
WriteCmdXLCD(SHIFT_DISP_LEFT);
OpenI2C(MASTER, SLEW_OFF); // Initialize I2C module
SSPADD = 9; // Baud rate clock
IdleI2C();
StartI2C();
while (SSPCON2bits.SEN);
Screen();
}
// *************************** functions **********************************
void show_menu(void) {
for (;;) {
if (selected > 4) {
line_cnt = 4;
} else {
line_cnt = 1;
}
for (unsigned char a = 1; a <= 4; a++) {
lcd_gotoxy(line_cnt, 3);
putrsXLCD(menu[line_cnt].text);
line_cnt++;
}
lcd_gotoxy(selected, 1);
putrsXLCD(">");
// ENTER
if (PORTAbits.RA1 == 0) {
__delay_ms(20);
while (PORTAbits.RA1 == 0);
if (menu[selected].fp == 0) {
selected = menu[selected].enter;
ClearXLCD();
} else {
menu[selected].fp();
}
}
// UP
if (PORTAbits.RA2 == 0) {
__delay_ms(20);
while (PORTAbits.RA2 == 0);
selected = menu[selected].up;
ClearXLCD();
}
// DOWN
if (PORTAbits.RA3 == 0) {
__delay_ms(20);
while (PORTAbits.RA3 == 0);
selected = menu[selected].down;
ClearXLCD();
}
}
}
void Screen(void){
ClearXLCD();
for (;;) {
//Read Time and Date, when simulating with proteus, it will pick up the system Clock
//from your PC and might display the AM if your PC time is in 24Hrs mode
hour = read_ds1307(0x02); //Read Hour
hr = hour & 0b00011111;
minute = read_ds1307(0x01); //Read minutes
second = read_ds1307(0x00); //Read seconds
time[0] = MSB(hr);
time[1] = LSB(hr);
time[3] = MSB(minute);
time[4] = LSB(minute);
time[6] = MSB(second);
time[7] = LSB(second);
//Display Time and Date in 12Hrs Mode (with PM or AM)
lcd_gotoxy(1, 1);
putrsXLCD(time);
// Poll Enter switch
if (PORTAbits.RA1 == 0) {
__delay_ms(20);
while (PORTAbits.RA2 == 0);
show_menu();
}
// Check Alarms
if (hr >= ON_Blue_Hour) {
if (minute >= ON_Blue_Minute) {
PORTBbits.RB1 = 1;
}
}
}
}
void Set_Time(void) {
ClearXLCD();
lcd_gotoxy(1, 1);
putrsXLCD("Set time");
while (BusyXLCD()); // Wait if LCD busy
putrsXLCD("Works!");
Delay_100ms(10);
ClearXLCD();
}
void Lights_ON_OFF(void) {
ClearXLCD();
do {
lcd_gotoxy(1, 3); // Line 1
putrsXLCD("Blue ON");
ON_Blue[0] = MSB(ON_Blue_Hour);
ON_Blue[1] = LSB(ON_Blue_Hour);
ON_Blue[3] = MSB(ON_Blue_Minute);
ON_Blue[4] = LSB(ON_Blue_Minute);
lcd_gotoxy(1, 11);
putrsXLCD(ON_Blue);
OFF_Blue[0] = MSB(OFF_Blue_Hour);
OFF_Blue[1] = LSB(OFF_Blue_Hour);
OFF_Blue[3] = MSB(OFF_Blue_Minute);
OFF_Blue[4] = LSB(OFF_Blue_Minute);
lcd_gotoxy(2, 3); // Line 2
putrsXLCD("Blue OFF");
lcd_gotoxy(2, 12);
putrsXLCD(OFF_Blue);
ON_Main[0] = MSB(ON_Main_Hour);
ON_Main[1] = LSB(ON_Main_Hour);
ON_Main[3] = MSB(ON_Main_Minute);
ON_Main[4] = LSB(ON_Main_Minute);
lcd_gotoxy(3, 3); // Line3
putrsXLCD("Main ON");
lcd_gotoxy(3, 11);
putrsXLCD(ON_Main);
OFF_Main[0] = MSB(OFF_Main_Hour);
OFF_Main[1] = LSB(OFF_Main_Hour);
OFF_Main[3] = MSB(OFF_Main_Minute);
OFF_Main[4] = LSB(OFF_Main_Minute);
lcd_gotoxy(4, 3); // Line 4
putrsXLCD("Blue OFF");
lcd_gotoxy(4, 12);
putrsXLCD(OFF_Main);
} while (1);
}
void Lights_Colour(void) {
ClearXLCD();
putrsXLCD("Colour");
while (BusyXLCD()); // Wait if LCD busy
putrsXLCD("Works!");
Delay_100ms(10);
ClearXLCD();
}
void Lights_Fade(void) {
ClearXLCD();
putrsXLCD("Fade");
while (BusyXLCD()); // Wait if LCD busy
putrsXLCD("Works!");
Delay_100ms(10);
ClearXLCD();
}
char
absolute(char a) {
if (a < 0)
return -a;
return a;
}
unsigned short read_ds1307(unsigned short address) //call this function to read date and time
//from the date and time registers.
{
char r_data;
StartI2C(); // Start condition I2C on bus
IdleI2C();
WriteI2C(0xD0); // addresses the chip
IdleI2C();
WriteI2C(address); // write register address
IdleI2C();
StopI2C(); // Stop condition I2C on bus
RestartI2C(); // Start condition I2C on bus
IdleI2C();
WriteI2C(0xD1); // addresses the chip with a read bit
IdleI2C();
r_data = ReadI2C(); // read the value from the RTC and store in result
IdleI2C();
NotAckI2C(); // Not Acknowledge condition.
IdleI2C();
StopI2C(); // Stop condition I2C on bus
return (r_data);
}
void write_ds1307(unsigned short address, unsigned short w_data) //call this function to write date and time
//to the date and time registers.
{
StartI2C(); // Start condition I2C on bus
IdleI2C();
WriteI2C(0xD0); // addresses the chip
IdleI2C();
WriteI2C(address); // write register address
IdleI2C();
WriteI2C(w_data); // write register address
IdleI2C();
StopI2C(); // Stop condition I2C on bus
}