Blackpool Computer Club is sponsored by: ThisHosting.Rocks

User Tools

Site Tools


code_template

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

code_template [2018/08/09 11:15] (current)
admin created
Line 1: Line 1:
 +Click on file name in tab to download the code
 +
 +<file c foo.c>/*
 + * flashLED.c
 + *
 + ​* ​ Created on: 21-Feb-2011
 + ​* ​     Author: user
 + ​* ​
 + */
 +
 +#include <​avr/​io.h>​
 +#include <​util/​delay.h>​
 +
 +// This program will turn the LEDs on for 100ms,
 +// then off for 200ms, endlessly.
 +
 +int main(void)
 +{
 +  // Set Port B pins for 3 and 4 as outputs
 +  // PORTB bit 3 = physical pin #2 on the ATTINY45
 +  // PORTB bit 4 = physical pin #3 on the ATTINY45
 +
 +  DDRB = 0x18;  // In binary this is 0001 1000 (note that is bit 3 and 4)
 +  // AVR-GCC also would accept 0b00011000, by the way.
 +
 +  // Set up a forever loop using your favorite C-style '​for'​ loop
 +  for ( ; 1==1 ; )  // loop while 1 equals 1
 +  {
 +    // Set Port B pins for 3 and 4 as HIGH (i.e. turn the LEDs on)
 +    PORTB = 0x18;   // If we wanted only PB4 on, it'd be PORTB=0x10
 +
 +    // Use a function (defined in delay.h) to pause 100 milliseconds
 +    _delay_ms(100);​
 +
 +    // Set PORTB to be all LOWs (i.e. turn the LEDs off)
 +    PORTB = 0x00;
 +
 +    // Delay for a 200ms
 +    _delay_ms(200);​
 +  }
 +
 +return 1;
 +}
 + </​file>​
  
code_template.txt ยท Last modified: 2018/08/09 11:15 by admin