AVR StampPlotExample.c: Rozdiel medzi revíziami
Zo stránky SensorWiki
Bez shrnutí editace |
Bez shrnutí editace |
||
(4 medziľahlé úpravy od rovnakého používateľa nie sú zobrazené.) | |||
Riadok 1: | Riadok 1: | ||
<source lang="c"> | <source lang="c"> | ||
#include <stdio.h> | #include <stdio.h> | ||
#include < | #include <stdlib.h> | ||
#include < | #include <math.h> | ||
#include | #include <avr/io.h> | ||
#include <util/delay.h> | |||
#define BAUDRATE 9600 | |||
#define BAUD_PRESCALE (((F_CPU / (BAUDRATE * 16UL))) - 1) | |||
void inituart(void) /* Initialize UART */ | |||
{ | |||
UBRR0 = (unsigned char)BAUD_PRESCALE; // Set baud rate | |||
UCSR0B = (1 << RXEN0) | (1 << TXEN0); // Enable receiver and transmitter | |||
UCSR0C = (1<<USBS0)|(3<<UCSZ00); // Set format: 8data, 2stop bit | |||
} | |||
void sendchar (char c) | |||
{ | |||
while ( !( UCSR0A & (1<<UDRE0)) ) ; // Wait for empty transmit buffer | |||
UDR0 = c; // Send the byte | |||
} | |||
FILE mystdout = FDEV_SETUP_STREAM(sendchar, NULL, _FDEV_SETUP_WRITE); | |||
// 'sendchar' je nova funkcia pre jeden znak | |||
/ | int main(void) | ||
{ | |||
unsigned char c; | |||
float x=0.0; | |||
inituart(); // Inicializacia seriovej linky | |||
stdout = &mystdout; // Odteraz funguje printf(); | |||
printf("!RSET\r"); // Reset vymaze okno | |||
for ( | printf("!TITL Lahky Priklad\r"); // Nazov okna | ||
printf("!SPAN -5, 45\r"); // Rozpatie pre analogove veliciny | |||
printf("!PNTS 1250\r"); // Pocet bodov ktore kreslime | |||
printf("!TMAX 30\r"); // Casova os 30 sekund | |||
printf("!MAXS\r"); // Na konci stoj | |||
printf("!TSMP ON\r"); // Casove znacky ANO | |||
printf("!CLRM\r"); // Vymaz okienko na spravy | |||
printf("!PLOT ON\r"); // Kreslenie ANO | |||
printf("!RSET\r"); // Restart s novymi parametrami | |||
_delay_ms(200); // Kratka 200 ms prestavka aby sa | |||
// vyprazdnil buffer v PC | |||
for (;;) | |||
{ | |||
c = (char)rand(); | |||
printf("%d,%d\r",(int)(100*(sin(x)+1)),c); | |||
if (c>245) | |||
printf("Alarm! Temperature HIGH!!!\r"); | |||
if (c<5) | |||
printf("Alarm! Temperature LOW!!!\r"); | |||
_delay_ms(300); | |||
x=x+0.1; | |||
} | } | ||
return 0; | |||
} /* End Of Main */ | } /* End Of Main */ | ||
</source> | </source> | ||
Riadok 50: | Riadok 63: | ||
[[Category: AVR]][[Category: CAD_RS]] | [[Category: AVR]][[Category: CAD_RS]] |
Aktuálna revízia z 20:23, 11. november 2011
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <avr/io.h>
#include <util/delay.h>
#define BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (BAUDRATE * 16UL))) - 1)
void inituart(void) /* Initialize UART */
{
UBRR0 = (unsigned char)BAUD_PRESCALE; // Set baud rate
UCSR0B = (1 << RXEN0) | (1 << TXEN0); // Enable receiver and transmitter
UCSR0C = (1<<USBS0)|(3<<UCSZ00); // Set format: 8data, 2stop bit
}
void sendchar (char c)
{
while ( !( UCSR0A & (1<<UDRE0)) ) ; // Wait for empty transmit buffer
UDR0 = c; // Send the byte
}
FILE mystdout = FDEV_SETUP_STREAM(sendchar, NULL, _FDEV_SETUP_WRITE);
// 'sendchar' je nova funkcia pre jeden znak
int main(void)
{
unsigned char c;
float x=0.0;
inituart(); // Inicializacia seriovej linky
stdout = &mystdout; // Odteraz funguje printf();
printf("!RSET\r"); // Reset vymaze okno
printf("!TITL Lahky Priklad\r"); // Nazov okna
printf("!SPAN -5, 45\r"); // Rozpatie pre analogove veliciny
printf("!PNTS 1250\r"); // Pocet bodov ktore kreslime
printf("!TMAX 30\r"); // Casova os 30 sekund
printf("!MAXS\r"); // Na konci stoj
printf("!TSMP ON\r"); // Casove znacky ANO
printf("!CLRM\r"); // Vymaz okienko na spravy
printf("!PLOT ON\r"); // Kreslenie ANO
printf("!RSET\r"); // Restart s novymi parametrami
_delay_ms(200); // Kratka 200 ms prestavka aby sa
// vyprazdnil buffer v PC
for (;;)
{
c = (char)rand();
printf("%d,%d\r",(int)(100*(sin(x)+1)),c);
if (c>245)
printf("Alarm! Temperature HIGH!!!\r");
if (c<5)
printf("Alarm! Temperature LOW!!!\r");
_delay_ms(300);
x=x+0.1;
}
return 0;
} /* End Of Main */