Microcontroller programmerings problem
Hejsa, jeg har fået stillet en opgave, nemlig at jeg skal programmere en Atmel 90S8535 microcontroller til at måle temperaturen ved hjælp af en nogle eksterne sensorer som sidder på port A, det skal så igennem ADC'en så processoren forstår det. Problemet er at jeg ikke kan få det til at virke, og vi har fundet ud af at det er programmet der er problemet. Så er der nogle stykker der kender til sådan noget her, der kan hjælpe mig? Her følger hele koden til til programmet:/*********************************************
This program was produced by the
CodeWizardAVR V1.24.0 Evaluation
Automatic Program Generator
© Copyright 1998-2003 HP InfoTech s.r.l.
http://www.hpinfotech.ro
e-mail:office@hpinfotech.ro
Project :
Version :
Date : 02-06-2004
Author : Freeware, for non-commercial use only
Company :
Comments:
Chip type : AT90S8535
Clock frequency : 8,000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 128
*********************************************/
#include <90s8535.h>
#include <LCD-display.h>
#include <stdio.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15
#endasm
#include <lcd.h>
// Declare your global variables here
void front()
{
lcd_clear(); //Slet display (kan udelades her).
lcd_gotoxy(1,0); //Start 1.linie, 2.tegn (kan udelades her).
lcd_putsf("Temperaturstyring"); //Skriv tekst til display.
lcd_gotoxy(3,1); //Start 2.linie, 4.tegn.
lcd_putsf("v. 0,2 beta"); //Skriv tekst til display.
lcd_gotoxy(3,3); //Start 3.linie, 4.tegn.
lcd_putsf("Vælg funktion"); //Skriv tekst til display.
}
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input;
// Start the AD conversion
ADCSR|=0x40;
// Wait for the AD conversion to complete
while ((ADCSR & 0x10)==0);
ADCSR|=0x10;
return ADCW;
}
void main(void)
{
// Declare your local variables here
unsigned char lcd_buffer1[30];
// Input/Output Ports initialization
// Port A initialization
// Func0=Out Func1=Out Func2=Out Func3=Out Func4=Out Func5=Out Func6=Out Func7=Out
// State0=0 State1=0 State2=0 State3=0 State4=0 State5=0 State6=0 State7=0
PORTA=0x00;
DDRA=0xFF;
// Port B initialization
// Func0=Out Func1=Out Func2=Out Func3=Out Func4=Out Func5=Out Func6=Out Func7=Out
// State0=0 State1=0 State2=0 State3=0 State4=0 State5=0 State6=0 State7=0
PORTB=0xFF;
DDRB=0xFF;
// Port C initialization
// Func0=Out Func1=Out Func2=Out Func3=Out Func4=Out Func5=Out Func6=Out Func7=Out
// State0=0 State1=0 State2=0 State3=0 State4=0 State5=0 State6=0 State7=0
PORTC=0x00;
DDRC=0xFF;
// Port D initialization
// Func0=Out Func1=Out Func2=Out Func3=Out Func4=Out Func5=Out Func6=Out Func7=Out
// State0=0 State1=0 State2=0 State3=0 State4=0 State5=0 State6=0 State7=0
PORTD=0x00;
DDRD=0xFF;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
GIMSK=0x00;
MCUCR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
// Analog Comparator Output: Off
ACSR=0x80;
// LCD module initialization
lcd_init(20);
// ADC initialization
// ADC Clock frequency: 125,000 kHz
ADCSR=0x86;
front();
while (1)
{
if(PINA.4)
{
read_adc(0);
lcd_clear();
lcd_gotoxy(6,0);
lcd_putsf("Status");
lcd_gotoxy(4,2);
sprintf(lcd_buffer1,"%u",ADCW);
lcd_puts(lcd_buffer1);
}
if(PINA.5)
{
lcd_clear();
lcd_gotoxy(4,0);
lcd_putsf("Alarmgrænse");
}
if(PINA.6)
{
lcd_clear();
lcd_gotoxy(4,0);
lcd_putsf("Svinginger");
}
if(PINA.7)
{
front();
}
};
}