Hello,
I have a big problem with programming for Board MCB2300 and Micro LPC2388.
I want to design a calculator and this is my code :
---------------------------------------------------------
#include <lpc23xx.h> #include <stdio.h> // Alphanumeric LCD Module functions #include <alcd.h>
// Declare your global variables here
int row[4]={0xfe,0xfd,0xfb,0xf7},num1=0,num2=0; char buffer[16]; bit flag2=0; bit flag=0; void setNum(int n); void sum(); void mul(); void dev(); void sub();
void main(void) { int i=0,mode=0;
// Declare your local variables here
// Input/Output Ports initialization // Port A initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTA=0x00; DDRA=0x00;
// Port B initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTB=0x00; DDRB=0x00;
// Port C initialization // Func7=In Func6=In Func5=In Func4=In Func3=Out Func2=Out Func1=Out Func0=Out // State7=T State6=T State5=T State4=T State3=0 State2=0 State1=0 State0=0 PORTC=0xff; DDRC=0x0F;
// Port D initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTD=0x00; DDRD=0x00;
// Timer/Counter 0 initialization // Clock source: System Clock // Clock value: Timer 0 Stopped // Mode: Normal top=0xFF // OC0 output: Disconnected TCCR0=0x00; TCNT0=0x00; OCR0=0x00;
// Timer/Counter 1 initialization // Clock source: System Clock // Clock value: Timer1 Stopped // Mode: Normal top=0xFFFF // OC1A output: Discon. // OC1B output: Discon. // Noise Canceler: Off // Input Capture on Falling Edge // Timer1 Overflow Interrupt: Off // Input Capture Interrupt: Off // Compare A Match Interrupt: Off // Compare B Match Interrupt: Off TCCR1A=0x00; TCCR1B=0x00; TCNT1H=0x00; TCNT1L=0x00; ICR1H=0x00; ICR1L=0x00; OCR1AH=0x00; OCR1AL=0x00; OCR1BH=0x00; OCR1BL=0x00;
// Timer/Counter 2 initialization // Clock source: System Clock // Clock value: Timer2 Stopped // Mode: Normal top=0xFF // OC2 output: Disconnected ASSR=0x00; TCCR2=0x00; TCNT2=0x00; OCR2=0x00;
// External Interrupt(s) initialization // INT0: Off // INT1: Off // INT2: Off MCUCR=0x00; MCUCSR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x00;
// USART initialization // USART disabled UCSRB=0x00;
// Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80; SFIOR=0x00;
// ADC initialization // ADC disabled ADCSRA=0x00;
// SPI initialization // SPI disabled SPCR=0x00;
// TWI initialization // TWI disabled TWCR=0x00;
// Alphanumeric LCD initialization // Connections specified in the // Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu: // RS - PORTA Bit 0 // RD - PORTA Bit 1 // EN - PORTA Bit 2 // D4 - PORTA Bit 4 // D5 - PORTA Bit 5 // D6 - PORTA Bit 6 // D7 - PORTA Bit 7 // Characters/line: 16 lcd_init(16);
while (1) { // Place your code here for(i=0;i<4;i++) { PORTC=row[i]; if(i==0) { if(PINC.4==0) { while(PINC.4==0) {} lcd_putchar('7'); setNum(7); } if(PINC.5==0) { while(PINC.5==0) {} lcd_putchar('8'); setNum(8); } if(PINC.6==0) { while(PINC.6==0) {} lcd_putchar('9'); setNum(9); } if(PINC.7==0) { while(PINC.7==0) {} if(flag==0 || flag2==1) { flag=1; lcd_putchar('/'); flag2=0; mode=1; } } } else { if(i==1) { if(PINC.4==0) { while(PINC.4==0) {} lcd_putchar('4'); setNum(4); } if(PINC.5==0) { while(PINC.5==0) {} lcd_putchar('5'); setNum(5); } if(PINC.6==0) { while(PINC.6==0) {} lcd_putchar('6'); setNum(6); } if(PINC.7==0) { while(PINC.7==0) {} if(flag==0 || flag2==1) { flag=1; flag2=0; lcd_putchar('*'); mode=2; } } } else { if(i==2) { if(PINC.4==0) { while(PINC.4==0) {} lcd_putchar('1'); setNum(1); } if(PINC.5==0) { while(PINC.5==0) {} lcd_putchar('2'); setNum(2); } if(PINC.6==0) { while(PINC.6==0) {} lcd_putchar('3'); setNum(3); } if(PINC.7==0) { while(PINC.7==0) {} if(flag==0 || flag2==1) { flag=1; flag2=0; lcd_putchar('-'); mode=3; } } } else { if(i==3) { if(PINC.4==0) { while(PINC.4==0) {} num1=0; num2=0; flag=0; flag2=0; lcd_clear(); } if(PINC.5==0) { while(PINC.5==0) {} lcd_putchar('0'); setNum(0); } if(PINC.6==0) { while(PINC.6==0) {} switch(mode) { case 1: { dev(); break; } case 2: { mul(); break; } case 3: { sub(); break; } case 4: { sum(); break; } } } if(PINC.7==0) { while(PINC.7==0) {} if(flag==0 || flag2==1) { flag=1; flag2=0; lcd_putchar('+'); mode=4; } } } } } }
} } }
void setNum(int n) {
if(flag==1) { num2=(num2)*10; num2+=n; } else if(flag==0) { num1=(num1)*10; num1+=n; } }
void sum() { int answer=num1+num2; num1=answer; num2=0; lcd_clear(); sprintf(buffer,"%d",answer); lcd_puts(buffer); flag2=1; }
void mul() { int answer=num1*num2; num2=0; num1=answer; lcd_clear(); sprintf(buffer,"%d",answer); lcd_puts(buffer); flag2=1; }
void dev() { int answer=num1/num2; num2=0; lcd_clear(); num1=answer; sprintf(buffer,"%d",answer); lcd_puts(buffer); flag2=1; }
void sub() { int answer=num1-num2; num1=answer; num2=0; lcd_clear(); sprintf(buffer,"%d",answer); lcd_puts(buffer); flag2=1; }
-------------------------------------------------------------------
I have errors about afx and lcd ,When I compile it.
Can you please help me? what do I need?
Please correct this Cod for me. I want to use the Keypad.
Thank You
Put the source code between PRE tags, if it doesn't look good in preview mode, it won't look good when posted.
Break the problem in to small pieces you can understand and test.