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] MicroC AC Controller syntax problem "pic16f88"

Status
Not open for further replies.

mcu52

Newbie level 1
Joined
Mar 18, 2012
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,287
MicroC AC Controller syntax problem "pic16f88"
Hi, i'm having a problem where i got syntax error for the following code. Can anyone help.
Code:
//********************************************************************** 

/*
	AC Controller
*/

//********************************************************************** 

static	unsigned	short	controlFlag;
static	unsigned	short	sleepTimeTemp;
static	unsigned	short	sleepTime;

void	interrupt()
{
	if (INTCON.T0IF == 1) {		
		INTCON.T0IF = 0;
		TMR0 = 170;
		//
		if (controlFlag == 1) {
			if (sleepTimeTemp > 0) {
				if (sleepTimeTemp == 1) {
					PORTA.F2 = 1;
				}
				sleepTimeTemp--;
			} else {
				PORTA.F2 = 0;
			}
		}
	}
	if (PIR1.TMR1IF == 1) {		// 200msec
		PIR1.TMR1IF = 0;
		PORTB.F1 = ~PORTB.F1;
	}
	if (INTCON.INTF == 1) {		// 8msec (60Hz)	
		INTCON.INTF = 0;
		sleepTimeTemp = sleepTime;
	}
}

//********************************************************************** 

void	Pwm_Change_DutyEx(unsigned int duty_ratio)
{
    CCPR1L = duty_ratio >> 2;
    CCP1CON.F6 = duty_ratio & 0b00000001;
    CCP1CON.F7 = (duty_ratio & 0b00000010) >> 1; 
}

//********************************************************************** 

void	main()
{
	static	unsigned	int		ad1;
	static	unsigned	short	cnt, i;
	static	unsigned	long	l;
	static	unsigned	char	buf[10];
	//
	CMCON = 0b00000111;			 
	ANSEL = 0b00000010;			
	TRISA = 0b00111010;			 
	TRISB = 0b00000101;			 
	OSCCON = 0b01110000;		
	OPTION_REG = 0b00001000;	
	T1CON = 0b00110001;			
	OPTION_REG.INTEDG = 0;		
	INTCON.GIE = 0;				
	INTCON.PEIE = 1;			// Peripheral Interrupt Enable
	INTCON.TMR0IE = 1;			// TMR0 Overflow Interrupt Enable
	INTCON.TMR0IF = 0;			// TMR0 Overflow Interrupt Flag
	INTCON.INTE = 1;			// RB0/INT External Interrupt Enable
	PIE1.TMR1IE = 1;			// TMR1 Overflow Interrupt Enable
	PIR1.TMR1IF = 0;			// TMR1 Overflow Interrupt Flag
	T2CON.T2CKPS0 = 0;			
	T2CON.T2CKPS1 = 0;			
	//
	Pwm_Init(2000);	// 2Khz
	Pwm_Change_DutyEx(1024 / 2);
	//
	Lcd_Custom_Config(&PORTB,4,5,6,7,&PORTA,0,7,6);
	TRISB = 0b00000101;
	TRISA = 0b00111010;
	//
	controlFlag = 0;
	sleepTime = 0;
	sleepTimeTemp = 0;
	//
	Lcd_Custom_Cmd(LCD_CURSOR_OFF);
	for (cnt = 0; cnt < 5; cnt++) {
		Lcd_Custom_Out(1, 1, "AC contr");
		Lcd_Custom_Out(2, 1, "ol  R1.1");
		Pwm_Start();
		Delay_ms(200);	
		Pwm_Stop();
		Lcd_Custom_Cmd(LCD_CLEAR);
		Delay_ms(200);
	}
	//
	INTCON.GIE = 1;	
	//
	while (1) {
		//
		if (PORTA.F3 == 1) {
			ad1 = Adc_Read(1);				
			sleepTime = 127 - (ad1 / 8);	
		} else {
			if (PORTA.F4 == 0) {		
				if (sleepTime < 127) 
					sleepTime++;
				
				Pwm_Start();
				Delay_ms(50);	
				Pwm_Stop();
			}
			if (PORTA.F5 == 0) {			
				if (sleepTime > 0) 
					sleepTime--;
				// 
				Pwm_Start();
				Delay_ms(50);	
				Pwm_Stop();
			}
		}
		//
		switch (sleepTime) {
		case 0:		
			controlFlag = 0;
			PORTA.F2 = 1;
			break;
		case 127:	
			controlFlag = 0;
			PORTA.F2 = 0;
			break;
		default:
			controlFlag = 1;
		}
		// 
		cnt = (127 - sleepTime) / 10;		// 0...12
		for (i = 1; i < 9; i++) {
			if (cnt > 0) {
				cnt--;
				Lcd_Custom_Chr(1, i, 0xFF);
			} else {
				Lcd_Custom_Chr(1, i, ' ');
			}
		}
		for (i = 1; i < 5; i++) {
			if (cnt > 0) {
				cnt--;
				Lcd_Custom_Chr(2, i, 0xFF);
			} else {
				Lcd_Custom_Chr(2, i, ' ');
			}
		}
		// 
		l = (long)sleepTime; 
		l = ((127 - sleepTime) * 100) / 127;
		WordToStr(l, buf);
		buf[5] = '%';
		buf[6] = 0x00;
		Lcd_Custom_Out(2, 5, &buf[2]);
		//
		Delay_ms(1);
	}
}

//**********************************************************************
T5.jpg

the problem saying that "is not applicable to these operands 'INTCON, Undeclared identifier 'Lcd_Custom_Config' in expression "

Can anyone help. thanks.
 
Last edited by a moderator:

Zip and post the complete mikroC Project files so that the code can be fixed. There are a lot of errors because you are using mikroC code with mikroC PRO Compiler. mikroC is very old compiler. The library functions have changed in mikroC Pro Compiler.

Try this code. Still LCD functions have to be fixed. It can be done if you zip and post your Circuit (LCD connections) and mikroC project files.


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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//********************************************************************** 
 
/*
    AC Controller
*/
 
//********************************************************************** 
 
static  unsigned    short   controlFlag;
static  unsigned    short   sleepTimeTemp;
static  unsigned    short   sleepTime;
 
void    interrupt()
{
    if (TMR0IF_bit) {       
        TMR0IF_bit = 0;
        TMR0 = 170;
        //
        if (controlFlag == 1) {
            if (sleepTimeTemp > 0) {
                if (sleepTimeTemp == 1) {
                    PORTA.F2 = 1;
                }
                sleepTimeTemp--;
            } else {
                PORTA.F2 = 0;
            }
        }
    }
    if (TMR1IF_bit) {       // 200msec
        TMR1IF_bit = 0;
        PORTB.F1 = ~PORTB.F1;
    }
    if (INTF_bit) {     // 8msec (60Hz) 
        INTF_bit = 0;
        sleepTimeTemp = sleepTime;
    }
}
 
//********************************************************************** 
/*
void    PWM_Set_Duty(unsigned int duty_ratio)
{
    CCPR1L = duty_ratio >> 2;
    CCP1CON.F6 = duty_ratio & 0b00000001;
    CCP1CON.F7 = (duty_ratio & 0b00000010) >> 1; 
}
*/
//********************************************************************** 
 
void    main()
{
    static  unsigned    int     ad1;
    static  unsigned    short   cnt, i;
    static  unsigned    long    l;
    static  unsigned    char    buf[10];
    //
    CMCON = 0b00000111;          
    ANSEL = 0b00000010;         
    TRISA = 0b00111010;          
    TRISB = 0b00000101;          
    OSCCON = 0b01110000;        
    OPTION_REG = 0b00001000;    
    T1CON = 0b00110001;         
    OPTION_REG.INTEDG = 0;      
    INTCON.GIE = 0;             
    INTCON.PEIE = 1;            // Peripheral Interrupt Enable
    INTCON.TMR0IE = 1;          // TMR0 Overflow Interrupt Enable
    INTCON.TMR0IF = 0;          // TMR0 Overflow Interrupt Flag
    INTCON.INTE = 1;            // RB0/INT External Interrupt Enable
    PIE1.TMR1IE = 1;            // TMR1 Overflow Interrupt Enable
    PIR1.TMR1IF = 0;            // TMR1 Overflow Interrupt Flag
    T2CON.T2CKPS0 = 0;          
    T2CON.T2CKPS1 = 0;          
    //
    PWM1_Init(2000);    // 2Khz
    Pwm1_Set_Duty(127);
    //
    Lcd_Custom_Config(&PORTB,4,5,6,7,&PORTA,0,7,6);
    TRISB = 0b00000101;
    TRISA = 0b00111010;
    //
    controlFlag = 0;
    sleepTime = 0;
    sleepTimeTemp = 0;
    //
    LCD_Cmd(_LCD_CURSOR_OFF);
    for (cnt = 0; cnt < 5; cnt++) {
        LCD_Out(1, 1, "AC contr");
        LCD_Out(2, 1, "ol  R1.1");
        PWM1_Start();
        Delay_ms(200);  
        PWM1_Stop();
        Lcd_Cmd(_LCD_CLEAR);
        Delay_ms(200);
    }
    //
    INTCON.GIE = 1; 
    //
    while (1) {
        //
        if (PORTA.F3 == 1) {
            ad1 = Adc_Read(1);              
            sleepTime = 127 - (ad1 / 8);    
        } else {
            if (PORTA.F4 == 0) {        
                if (sleepTime < 127) 
                    sleepTime++;
                
                PWM1_Start();
                Delay_ms(50);   
                PWM1_Stop();
            }
            if (PORTA.F5 == 0) {            
                if (sleepTime > 0) 
                    sleepTime--;
                // 
                PWM1_Start();
                Delay_ms(50);   
                PWM1_Stop();
            }
        }
        //
        switch (sleepTime) {
        case 0:     
            controlFlag = 0;
            PORTA.F2 = 1;
            break;
        case 127:   
            controlFlag = 0;
            PORTA.F2 = 0;
            break;
        default:
            controlFlag = 1;
        }
        // 
        cnt = (127 - sleepTime) / 10;       // 0...12
        for (i = 1; i < 9; i++) {
            if (cnt > 0) {
                cnt--;
                Lcd_Chr(1, i, 0xFF);
            } else {
                Lcd_Chr(1, i, ' ');
            }
        }
        for (i = 1; i < 5; i++) {
            if (cnt > 0) {
                cnt--;
                Lcd_Chr(2, i, 0xFF);
            } else {
                Lcd_Chr(2, i, ' ');
            }
        }
        // 
        l = (long)sleepTime; 
        l = ((127 - sleepTime) * 100) / 127;
        WordToStr(l, buf);
        buf[5] = '%';
        buf[6] = 0x00;
        LCD_Out(2, 5, buf);
        //
        Delay_ms(1);
    }
}

 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top