Jericho_one
09.02.2007, 14:36
Hallo!
Ich bin gerade dabei einen Atmega 32 und ein Display mit ein paar Tasten zu programmieren - allerdings habe ich das Problem, dass die Hexdatei sehr groß wird und wenn ich noch mehr "dazuprogrammiere".
Im Moment hab ich lediglich das Display, die Tasten und eine Menüsteuerung drin:
//-------------------------------------------------------
void null(void){
int ebene1 = 0;
LCD_Clr();
LCD_WritePosString(0, 0, "Ebene1':", 1);
while ( ebene1 != 1 ){
if (PIND &(1 << PD2))
{
ebene1 = 1;
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
LCD_Clr();
}
}
}
//-------------------------------------------------------
void eins(void){
unsigned char ebene2 = 0;
LCD_Clr();
LCD_WritePosString(0, 0, "Ebene2:", 1);
while ( ebene2 != 1 ){
if (PIND &(1 << PD2))
{
ebene2 = 1;
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
LCD_Clr();
}
}
}
//-------------------------------------------------------
void zwei(void){
unsigned char ebene3 = 0;
LCD_Clr();
LCD_WritePosString(0, 0, "Ebene3", 1);
while ( ebene3 != 1 ){
if (PIND &(1 << PD2))
{
ebene3 = 1;
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
LCD_Clr();
}
}
}
//-------------------------------------------------------
void drei(void){
unsigned char ebene4 = 0;
LCD_Clr();
LCD_WritePosString(0, 0, "Ebene4:", 1);
while ( ebene4 != 1 ){
if (PIND &(1 << PD2))
{
ebene4 = 1;
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
LCD_Clr();
}
}
}
//-------------------------------------------------------
void men_grund(unsigned char zeile){
LCD_WritePosString(0, 0, "Drehzahl:", 1);
LCD_WritePosString(1, 0, "Drehmoment:", 1);
LCD_WritePosString(2, 0, "zahl", 1);
LCD_WritePosString(3, 0, "zahl2", 1);
LCD_WritePosString(zeile, 19, "#", 1);
}
//-------------------------------------------------------
void men(void){
unsigned char menue = 0;
int merker_zeile = 0;
unsigned char ebene = 0;
LCD_Clr();
men_grund(0);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
while ( menue != 1 ){
if (PIND &(1 << PD2)) //Menü
{
LCD_Clr();
menue=1;
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
}
if (PIND &(1 << PD3)){ //hoch
LCD_ClrLineXY(merker_zeile, 18, 19);
merker_zeile += 1;
if ( merker_zeile == 4)
{
merker_zeile = 0;
}
LCD_WritePosString(merker_zeile, 19, "#", 1);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
}
if (PIND &(1 << PD4)){ //runter
LCD_ClrLineXY(merker_zeile, 18, 19);
if ( merker_zeile == 0)
{
merker_zeile = 4;
}
merker_zeile -= 1;
LCD_WritePosString(merker_zeile, 19, "#", 1);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
}
if (PIND &(1 << PD5)){ //OK-Button
if (merker_zeile == 0) {
ebene =1;
null();
men_grund(0);
}
if (merker_zeile == 1) {
ebene=1;
eins();
men_grund(1);
}
if (merker_zeile == 2) {
ebene = 1;
zwei();
men_grund(2);
}
if (merker_zeile == 3) {
ebene = 1;
drei();
men_grund(3);
}
}
}
} // Menüende
//-------------------------------------------------------
int main(void){
_delay_ms(500);
_delay_ms(500);
_delay_ms(500);
LCD_Init(0);
LCD_Clr();
DDRD &=~( (1<<PD2) |(1<<PD3) | (1<<PD4) | (1<<PD5) | (1<<PD7) | (1<<PD6) ); //Pins auf active_high stellen
PORTD &=( (1<<PD2) |(1<<PD3) | (1<<PD4) | (1<<PD5) | (1<<PD7) | (1<<PD6) ); //Internen Pull-Up deaktivieren
DDRB |= (1<<PB7);
PORTB &= (1<<PB7);
while(1)
{
int i=0;
char zahl[3];
for(i=0; i<301; i=i+10)
{
if (PIND &(1 << PD2))
{
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
men();
}
itoa(i,zahl,10);
LCD_WritePosString(3, 5, zahl, 1);
LCD_WritePosString(3, 18, "NM", 1);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
}
}
return 0;
}
Wobei wenn ich lediglich das Display nutze und etwas darauf ausgeben lasse, die hex datei schon knapp 24kb groß wird.
Wie kann ich das ganze verbessern?
Danke
Ich bin gerade dabei einen Atmega 32 und ein Display mit ein paar Tasten zu programmieren - allerdings habe ich das Problem, dass die Hexdatei sehr groß wird und wenn ich noch mehr "dazuprogrammiere".
Im Moment hab ich lediglich das Display, die Tasten und eine Menüsteuerung drin:
//-------------------------------------------------------
void null(void){
int ebene1 = 0;
LCD_Clr();
LCD_WritePosString(0, 0, "Ebene1':", 1);
while ( ebene1 != 1 ){
if (PIND &(1 << PD2))
{
ebene1 = 1;
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
LCD_Clr();
}
}
}
//-------------------------------------------------------
void eins(void){
unsigned char ebene2 = 0;
LCD_Clr();
LCD_WritePosString(0, 0, "Ebene2:", 1);
while ( ebene2 != 1 ){
if (PIND &(1 << PD2))
{
ebene2 = 1;
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
LCD_Clr();
}
}
}
//-------------------------------------------------------
void zwei(void){
unsigned char ebene3 = 0;
LCD_Clr();
LCD_WritePosString(0, 0, "Ebene3", 1);
while ( ebene3 != 1 ){
if (PIND &(1 << PD2))
{
ebene3 = 1;
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
LCD_Clr();
}
}
}
//-------------------------------------------------------
void drei(void){
unsigned char ebene4 = 0;
LCD_Clr();
LCD_WritePosString(0, 0, "Ebene4:", 1);
while ( ebene4 != 1 ){
if (PIND &(1 << PD2))
{
ebene4 = 1;
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
LCD_Clr();
}
}
}
//-------------------------------------------------------
void men_grund(unsigned char zeile){
LCD_WritePosString(0, 0, "Drehzahl:", 1);
LCD_WritePosString(1, 0, "Drehmoment:", 1);
LCD_WritePosString(2, 0, "zahl", 1);
LCD_WritePosString(3, 0, "zahl2", 1);
LCD_WritePosString(zeile, 19, "#", 1);
}
//-------------------------------------------------------
void men(void){
unsigned char menue = 0;
int merker_zeile = 0;
unsigned char ebene = 0;
LCD_Clr();
men_grund(0);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
while ( menue != 1 ){
if (PIND &(1 << PD2)) //Menü
{
LCD_Clr();
menue=1;
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
}
if (PIND &(1 << PD3)){ //hoch
LCD_ClrLineXY(merker_zeile, 18, 19);
merker_zeile += 1;
if ( merker_zeile == 4)
{
merker_zeile = 0;
}
LCD_WritePosString(merker_zeile, 19, "#", 1);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
}
if (PIND &(1 << PD4)){ //runter
LCD_ClrLineXY(merker_zeile, 18, 19);
if ( merker_zeile == 0)
{
merker_zeile = 4;
}
merker_zeile -= 1;
LCD_WritePosString(merker_zeile, 19, "#", 1);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
}
if (PIND &(1 << PD5)){ //OK-Button
if (merker_zeile == 0) {
ebene =1;
null();
men_grund(0);
}
if (merker_zeile == 1) {
ebene=1;
eins();
men_grund(1);
}
if (merker_zeile == 2) {
ebene = 1;
zwei();
men_grund(2);
}
if (merker_zeile == 3) {
ebene = 1;
drei();
men_grund(3);
}
}
}
} // Menüende
//-------------------------------------------------------
int main(void){
_delay_ms(500);
_delay_ms(500);
_delay_ms(500);
LCD_Init(0);
LCD_Clr();
DDRD &=~( (1<<PD2) |(1<<PD3) | (1<<PD4) | (1<<PD5) | (1<<PD7) | (1<<PD6) ); //Pins auf active_high stellen
PORTD &=( (1<<PD2) |(1<<PD3) | (1<<PD4) | (1<<PD5) | (1<<PD7) | (1<<PD6) ); //Internen Pull-Up deaktivieren
DDRB |= (1<<PB7);
PORTB &= (1<<PB7);
while(1)
{
int i=0;
char zahl[3];
for(i=0; i<301; i=i+10)
{
if (PIND &(1 << PD2))
{
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
men();
}
itoa(i,zahl,10);
LCD_WritePosString(3, 5, zahl, 1);
LCD_WritePosString(3, 18, "NM", 1);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
}
}
return 0;
}
Wobei wenn ich lediglich das Display nutze und etwas darauf ausgeben lasse, die hex datei schon knapp 24kb groß wird.
Wie kann ich das ganze verbessern?
Danke