Hello all,
i got problem using PORTL on Atmega 2560, i got this error message when i code PORTL.6 = 1 :
"the first argument of the '.' operator must be of 'struct' or 'union' type"
this error only occur when i use PORTL, so anyone can help me ?
Here is my code :
#include#include #include #include #include #define MAX 0xFF int i; int encoder_axis_1, encoder_axis_2, encoder_axis_3, encoder_axis_4, encoder_axis_5; unsigned char lcd_encoder_axis_1[5], lcd_encoder_axis_2[5], lcd_encoder_axis_3[5], lcd_encoder_axis_4[5], lcd_encoder_axis_5[5]; void lcd_setting() { /* LCD on port C */ #asm .equ __lcd_port=0x08 ;PORTC #endasm } void oscillator_setting() { /* Crystal Division Factor : 1 */ #pragma optsize- CLKPR=0x80; CLKPR=0x00; #ifdef _OPTIMIZE_SIZE_ #pragma optsize+ #endif } void ports_setting() { /* board configuration F0F7K0K7 E0 A0 E7 A7 H0 J7 H7 uC J0 B4 C7 B7 C0 G0 G5 L0L7D0D7 */ PORTF =0b00000000; DDRF =0b11111111; //DDRK = 0xFF; //PORTK = 0x00; //PORT A //DDRA = 0b11111111; //PORT B //DDRB = 0b11111111; //PORT C //DDRC = 0b11111111; PORTD= 0b00000000; DDRD = 0b00000000; //PORTE = 0b00000000; DDRE = 0b11111111; //PORT G //DDRG = 0b11111111; //PORTH //DDRH = 0b11111110; //PORTJ //DDRJ = 0b11111110; //PORTL= 0b11111111; DDRL = 0b11111111; void timers_setting() { /* Timer/Counter 5 initialization Clock source: System Clock Clock value: 16000.000 kHz Mode: Ph. correct PWM top=00FFh OC5A output: Discon. OC5B output: Non-Inv. OC5C output: Non-Inv. Noise Canceler: On Input Capture on Falling Edge Timer 5 Overflow Interrupt: Off Input Capture Interrupt: Off Compare A Match Interrupt: Off Compare B Match Interrupt: Off Compare C Match Interrupt: Off */ TCCR5A=0x29; TCCR5B=0x81; TCNT5H=0x00; TCNT5L=0x00; ICR5H=0x00; ICR5L=0x00; OCR5AH=0x00; OCR5AL=0x00; OCR5BH=0x00; OCR5BL=0x00; OCR5CH=0x00; OCR5CL=0x00; } void interrupt_setting() { /* External Interrupt(s) initialization INT0: On INT0 Mode: Rising Edge INT1: On INT1 Mode: Rising Edge INT2: On INT2 Mode: Rising Edge INT3: On INT3 Mode: Rising Edge INT4: On INT4 Mode: Rising Edge INT5: On INT5 Mode: Rising Edge INT6: On INT6 Mode: Rising Edge INT7: On INT7 Mode: Rising Edge */ EICRA=0xFF; EICRB=0xFF; EIMSK=0xFF; EIFR=0xFF; } void motor_control(float duty_cycle_axis_1, int input_1_axis_1, int input_2_axis_1, float duty_cycle_axis_2, int input_1_axis_2, int input_2_axis_2) { /* Motor Control Axis_1 : PWM_axis_1 = PORTL.5 OCR5C input_1_axis_1 = PORTL.6 input_2_axis_1 = PORTL.7 Axis_2 : PWM_axis_2 = PORTL.4 OCR5B input_1_axis_2 = PORTL.2 input_2_axis_2 = PORTL.3 */ OCR5BH = MAX*duty_cycle_axis_2; OCR5BL = MAX*duty_cycle_axis_2; OCR5CH = MAX*duty_cycle_axis_1; OCR5CL = MAX*duty_cycle_axis_1; PORTL.2 = input_1_axis_2; PORTL.3 = input_2_axis_2; PORTL.6 = input_1_axis_1; PORTL.7 = input_2_axis_1; } void motor_stop() { motor_control(0,0,0,0,0,0); } interrupt [INT1] void ext_int1_isr(void) { encoder_axis_1++; } interrupt [INT2] void ext_int2_isr(void) { encoder_axis_2++; } interrupt [INT3] void ext_int3_isr(void) { encoder_axis_3++; } interrupt [INT4] void ext_int4_isr(void) { encoder_axis_4++; } interrupt [INT5] void ext_int5_isr(void) { encoder_axis_5++; } void test_encoder() { #asm ("sei"); while( encoder_axis_1 <= 145 ) { motor_control(0.5,1,0,0,1,0); } motor_stop(); #asm ("cli"); } void brake_axis_2_off() { PORTF.0 = 1; } void brake_axis_3_off() { PORTF.1 = 1; } void brake_axis_2_on() { PORTF.0 = 0; } void brake_axis_3_on() { PORTF.1 = 0; } void main(void) { lcd_init(16); oscillator_setting(); ports_setting(); timers_setting(); lcd_setting(); interrupt_setting(); lcd_gotoxy(0,0); lcd_putsf("ready"); delay_ms(3000); lcd_clear(); while(1) { brake_axis_2_off(); brake_axis_3_off(); } }
the compiler error on the motor_control function, at
PORTL.2 = input_1_axis_2; PORTL.3 = input_2_axis_2; PORTL.6 = input_1_axis_1; PORTL.7 = input_2_axis_1;
if i change to another port, the error gone, example
PORTE.2 = input_1_axis_2; PORTE.3 = input_2_axis_2; PORTE.6 = input_1_axis_1; PORTE.7 = input_2_axis_1;
:?: [/code]