ok ich habe dieses Programm auf dem Mikrochip am laufen:
//----------------------------------------------------------------------
---
// Titel : einfaches Beispielprogramm für den mySmartControl M8
//----------------------------------------------------------------------
---
// Funktion : einfaches Terminalprogram, schaltet Ports und I/O-Lines
// Schaltung : USB an PC, Virtueller Comport, COMx, 9600 Baud, 8,n,1
//----------------------------------------------------------------------
---
// Prozessor : ATmega8
// Takt : 3686400 Hz
// Sprache : C
// Datum : 16.11.2007
// Version : 1.2
//----------------------------------------------------------------------
---
// created by myAVR-CodeWizard
//----------------------------------------------------------------------
---
#define F_CPU 3686400
#include <avr\io.h>
#define BAUD 9600
//----------------------------------------------------------------------
// Titel : C-Funktion Zeichen zu UART senden.
// IN : char data
//----------------------------------------------------------------------
void uartPutChar(char data)
{
//warte bis UDR leer ist UCSRA / USR bei z.B.: 2313
while (!(UCSRA&32));
//sende
UDR=data;
}
void uartPutBin(char data)
{
//warte bis UDR leer ist UCSRA / USR bei z.B.: 2313
while (!(UCSRA&32));
//sende
if (data&1) uartPutChar('1'); else uartPutChar('0');
if (data&2) uartPutChar('1'); else uartPutChar('0');
if (data&4) uartPutChar('1'); else uartPutChar('0');
if (data&8) uartPutChar('1'); else uartPutChar('0');
if (data&16) uartPutChar('1'); else uartPutChar('0');
if (data&32) uartPutChar('1'); else uartPutChar('0');
if (data&64) uartPutChar('1'); else uartPutChar('0');
if (data&128) uartPutChar('1'); else uartPutChar('0');
}
//----------------------------------------------------------------------
// Titel : C-Funktion wartet auf Zeichen von UART.
// OUT : data
//----------------------------------------------------------------------
char uartGetChar()
{
char data=0;
//warte bis RX-complete RXC UCSRA / USR bei z.B.: AT090S2313
while (!(UCSRA&128));
//empfangen
data=UDR;
return data;
}
//----------------------------------------------------------------------
// Titel : C-Funktion wartet auf Zeichen von UART.
// OUT : data, error = keine Daten
//----------------------------------------------------------------------
bool error;
char uartIsChar()
{
char data=0;
error=true;
//chek RX-complete RXC UCSRA
if (!(UCSRA&128)) return 0;
//zeihen abholen
data=UDR;
error=false;
return data;
}
//----------------------------------------------------------------------
// Titel : C-Funktion Zeichenkette zu UART senden.
// IN : char *buffer, Zeichenkette mit NUll abgeschlossen
//----------------------------------------------------------------------
void uartPutString(char *buffer)
{
for (int i=0; buffer[i] !=0;i++)
uartPutChar (buffer[i]);
}
//----------------------------------------------------------------------
--
// Initialisierungen
//----------------------------------------------------------------------
--
void init()
{
// UART initialisieren
sbi(UCSRB,3); // TX aktiv
sbi(UCSRB,4); // RX aktivieren
UBRRL=(uint8_t)(F_CPU/(BAUD*16L))-1; // Baudrate festlegen
UBRRH=(uint8_t)((F_CPU/(BAUD*16L))-1)>>8; // Baudrate festlegen
//alles Ausgang
DDRB=0b00111111;
DDRC=0b11111111;
DDRD=0b11111110;
}
// Willkommen- und Hilfebeildschirm
void intro()
{
uartPutChar('\n');
for (int i=0;i<42;i++) uartPutChar('=');
uartPutString("\n mySmartControl Simple Term 1.2 \n www.myAVR.de");
uartPutChar('\n');
for (int i=0;i<42;i++) uartPutChar('-');
uartPutString("\nKommandos: zwei Byte, Kein Trennzeichen");
uartPutString("\n PB = PortB alle Bits ON");
uartPutString("\n pb = PortB alle Bits OFF");
uartPutString("\n PC = PortC alle Bits ON");
uartPutString("\n pc = PortC alle Bits OFF");
uartPutString("\n PD = PortD alle Bits ON");
uartPutString("\n Bx = PortB Bit X ON (X = 0..5)");
uartPutString("\n bx = PortB Bit X OFF (X = 0..5)");
uartPutString("\n Cx = PortC Bit X ON (X = 0..5)");
uartPutString("\n cx = PortC Bit X OFF (X = 0..5)");
uartPutString("\n Dx = PortD Bit X ON (X = 2..7)");
uartPutString("\n dx = PortD Bit X OFF (X = 2..7)");
uartPutString("\n iX = config Port(C,B,D) IN mit PullUP");
uartPutString("\n ix = config Port(c,b,d) IN ohne PullUP");
uartPutString("\n gx = get PIN(b,c,d)");
uartPutString("\n GX = get Port(B,C,D)");
uartPutString("\n Gx = get DDR(b,c,d)");
uartPutString("\n Ox = config Port(B,C,D) = OUT");
uartPutChar('\n');
for (int i=0;i<42;i++) uartPutChar('=');
}
////////////////////////////////////////////////////////////////////////
/////
// Main-Funktion
////////////////////////////////////////////////////////////////////////
/////
main()
{
unsigned char portBuffer[3]={0}; // B,C,D
char z1,z2;
init(); // Initialisierungen
intro();
while (true) // Mainloop-Begin
{
// Kommandos abfragen
z1=uartIsChar();
if (error) continue;
if (z1=='?')
{
intro();
continue;
}
z2=uartGetChar();
if (error) continue;
if (z1=='?')
{
intro();
continue;
}
switch (z1)
{
case 'I':
case 'i':
switch(z2)
{
case 'B':
DDRB=0x00;
PORTB=0xFF;
break;
case 'C':
DDRC=0x00;
PORTC=0xFF;
break;
case 'D':
DDRD=0b00000010;
PORTD=0b11111100;
break;
default:
uartPutChar('?');
break;
}
break;
case 'g':
switch(z2)
{
case 'B':
case 'b':
uartPutString("\nPinB=");
uartPutBin(PINB);
break;
case 'C':
case 'c':
uartPutString("\nPinC=");
uartPutBin(PINC);
break;
case 'D':
case 'd':
uartPutString("\nPinD=");
uartPutBin(PIND);
break;
}
break;
case 'G':
switch(z2)
{
case 'B':
uartPutString("\nPortB=");
uartPutBin(PINB);
break;
case 'C':
uartPutString("\nPortC=");
uartPutBin(PINC);
break;
case 'D':
uartPutString("\nPortD=");
uartPutBin(PIND);
break;
case 'b':
uartPutString("\nDDRB=");
uartPutBin(DDRB);
break;
case 'c':
uartPutString("\nDDRC=");
uartPutBin(DDRC);
break;
case 'd':
uartPutString("\nDDRD=");
uartPutBin(DDRD);
break;
default:
uartPutChar('?');
break;
}
break;
case 'O':
case 'o':
switch(z2)
{
case 'B':
DDRB=0b00111111;
break;
case 'C':
DDRC=0b11111111;
break;
case 'D':
DDRD=0b11111110;
break;
default:
uartPutChar('?');
break;
}
break;
case 'P':
case 'p':
switch(z2)
{
case 'B':
PORTB=0xFF;
break;
case 'C':
PORTC=0xFF;
break;
case 'D':
PORTD=0xFF;
break;
case 'b':
PORTB=0x00;
break;
case 'c':
PORTC=0x00;
break;
case 'd':
PORTD=0x00;
break;
default:
uartPutChar('?');
break;
}
break;
case 'B':
switch(z2)
{
case '0':
sbi(PORTB,0);
break;
case '1':
sbi(PORTB,1);
break;
case '2':
sbi(PORTB,2);
break;
case '3':
sbi(PORTB,3);
break;
case '4':
sbi(PORTB,4);
break;
case '5':
sbi(PORTB,5);
break;
default:
uartPutChar('?');
break;
}
break;
case 'C':
switch(z2)
{
case '0':
sbi(PORTC,0);
break;
case '1':
sbi(PORTC,1);
break;
case '2':
sbi(PORTC,2);
break;
case '3':
sbi(PORTC,3);
break;
case '4':
sbi(PORTC,4);
break;
case '5':
sbi(PORTC,5);
break;
default:
uartPutChar('?');
break;
}
break;
case 'D':
switch(z2)
{
case '2':
sbi(PORTD,2);
break;
case '3':
sbi(PORTD,3);
break;
case '4':
sbi(PORTD,4);
break;
case '5':
sbi(PORTD,5);
break;
case '6':
sbi(PORTD,6);
break;
case '7':
sbi(PORTD,7);
break;
default:
uartPutChar('?');
break;
}
break;
case 'b':
switch(z2)
{
case '0':
cbi(PORTB,0);
break;
case '1':
cbi(PORTB,1);
break;
case '2':
cbi(PORTB,2);
break;
case '3':
cbi(PORTB,3);
break;
case '4':
cbi(PORTB,4);
break;
case '5':
cbi(PORTB,5);
break;
default:
uartPutChar('?');
break;
}
break;
case 'c':
switch(z2)
{
case '0':
cbi(PORTC,0);
break;
case '1':
cbi(PORTC,1);
break;
case '2':
cbi(PORTC,2);
break;
case '3':
cbi(PORTC,3);
break;
case '4':
cbi(PORTC,4);
break;
case '5':
cbi(PORTC,5);
break;
default:
uartPutChar('?');
break;
}
break;
case 'd':
switch(z2)
{
case '2':
cbi(PORTD,2);
break;
case '3':
cbi(PORTD,3);
break;
case '4':
cbi(PORTD,4);
break;
case '5':
cbi(PORTD,5);
break;
case '6':
cbi(PORTD,6);
break;
case '7':
cbi(PORTD,7);
break;
default:
uartPutChar('?');
break;
}
break;
default:
uartPutChar('?');
break;
}
}
// Mainloop-Ende
}
//----------------------------------------------------------------------
-----