Operácie

AVR Example3.c: Rozdiel medzi revíziami

Z SensorWiki

Riadok 4: Riadok 4:
 
/*  Monoliticke mikropocitace - Priklad 1.3                                  */
 
/*  Monoliticke mikropocitace - Priklad 1.3                                  */
 
/*                                                                            */
 
/*                                                                            */
/*  Program zasvieti/zhasne LED na PD5 s periodou ???                        */
+
/*  Program zasvieti/zhasne zltu LED na PORTB.5 s periodou ?? [s]            */
 
/*                                                                            */
 
/*                                                                            */
 
/*  Autor: Richard Balogh <balogh@elf.stuba.sk>                              */
 
/*  Autor: Richard Balogh <balogh@elf.stuba.sk>                              */
 
/*  Historia:                                                                */
 
/*  Historia:                                                                */
 
/*            3. 3. 2006 prva pokusna verzia                                  */
 
/*            3. 3. 2006 prva pokusna verzia                                  */
 +
/*          12.10. 2012 upravene pre Acrob / Arduino (portD / portB)        */
 
/*  Verzia:                                                                  */
 
/*  Verzia:                                                                  */
 
/*            Pre studentov, chybajuce hodnoty                                */
 
/*            Pre studentov, chybajuce hodnoty                                */
Riadok 17: Riadok 18:
 
#include <avr/io.h>         
 
#include <avr/io.h>         
  
#define LEDon  PORTD &= ~(_BV(PD5)) // cbi(PORTD,PD5); ale cbi je nepodporovane  
+
#define LEDon  PORTB &= ~(_BV(5)) // cbi(PORTB,PB5); ale cbi je nepodporovane  
#define LEDoff (PORTD |= _BV(PD5))  // sbi(PORTD,PD5); ale sbi je nepodporovane
+
#define LEDoff (PORTB |= _BV(5))  // sbi(PORTB,PB5); ale sbi je nepodporovane
  
#define F_CPU 8000000
+
#define F_CPU 16000000
  
 
void delay_ms(unsigned int ms);
 
void delay_ms(unsigned int ms);
Riadok 27: Riadok 28:
 
{
 
{
 
                        
 
                        
     DDRD = 0x??;            // bin: ???? ????  1 = out, 0 = in
+
     DDRB = 0x??;            // bin: ???? ????  1 = out, 0 = in
     PORTD = 0x??;            // bin: ???? ????  1 = LED zhasni, 1 = pull-up ON
+
     PORTB = 0x??;            // bin: ???? ????  1 = LED zhasni, 1 = pull-up ON
  
 
     do{
 
     do{
 
    
 
    
         LEDoff;            // bin  PORTD + 0010 0000 = nastav PD5, LED OFF
+
         LEDoff;            // bin  PORTB + 0010 0000 = nastav PB5, LED OFF
 
         delay_ms(500);      // cakaj 500 ms (0,5 s)
 
         delay_ms(500);      // cakaj 500 ms (0,5 s)
         LEDon;              // bin: PORTD & 1101 1111 = vynuluj PD5, LED ON
+
         LEDon;              // bin: PORTD & 1101 1111 = vynuluj PB5, LED ON
 
         delay_ms(500);      // cakaj 500 ms (0,5 s)
 
         delay_ms(500);      // cakaj 500 ms (0,5 s)
 
          
 
          

Verzia zo dňa a času 07:11, 12. október 2012

/* ************************************************************************** */
/*                                                                            */
/*  Monoliticke mikropocitace - Priklad 1.3                                   */
/*                                                                            */
/*  Program zasvieti/zhasne zltu LED na PORTB.5 s periodou ?? [s]             */
/*                                                                            */
/*  Autor: Richard Balogh <balogh@elf.stuba.sk>                               */
/*  Historia:                                                                 */
/*            3. 3. 2006 prva pokusna verzia                                  */
/*           12.10. 2012 upravene pre Acrob / Arduino (portD / portB)         */
/*  Verzia:                                                                   */
/*            Pre studentov, chybajuce hodnoty                                */
/*  Prenositelnost:                                                           */
/*                                                                            */
/* ************************************************************************** */

#include <avr/io.h>        

#define LEDon  PORTB &= ~(_BV(5)) // cbi(PORTB,PB5); ale cbi je nepodporovane 
#define LEDoff (PORTB |= _BV(5))  // sbi(PORTB,PB5); ale sbi je nepodporovane

#define F_CPU 16000000

void delay_ms(unsigned int ms);

int main (void)
{
                      
     DDRB = 0x??;            // bin: ???? ????  1 = out, 0 = in
    PORTB = 0x??;            // bin: ???? ????  1 = LED zhasni, 1 = pull-up ON

    do{
   
         LEDoff;             // bin  PORTB + 0010 0000 = nastav PB5, LED OFF
         delay_ms(500);      // cakaj 500 ms (0,5 s)
         LEDon;              // bin: PORTD & 1101 1111 = vynuluj PB5, LED ON
         delay_ms(500);      // cakaj 500 ms (0,5 s)
         
    } while(1);             // toto rob stale dokola

    return (0);             // formalita, nikdy sem neprideme
}


void delay_ms(unsigned int ms)
{
  unsigned int index;

  while (ms)
  {
   index = F_CPU / ????;    // vypocitajte, kolko treba, aby sme dostali 1ms!!
        
   while (index)
   {
    asm volatile ("nop");
    index--;
   }

   ms--;
  }
}