Subversion Repositories svnkaklik

Rev

Rev 496 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 496 Rev 515
1
/*********************************************
1
/*********************************************
2
* vim: set sw=8 ts=8 si :
2
* vim: set sw=8 ts=8 si :
3
* Author: Guido Socher, Copyright: GPL 
3
* Author: Guido Socher, Copyright: GPL 
4
* This program is to test the led connected to
4
* This program is to test the led connected to
5
* PC5. 
5
* PC5. 
6
* See http://linuxfocus.org/English/November2004/
6
* See http://linuxfocus.org/English/November2004/
7
* for details.
7
* for details.
8
* Chip type           : ATMEGA644
8
* Chip type           : ATMEGA644
9
* Clock frequency     : Internal clock 1 Mhz (factory default)
9
* Clock frequency     : Internal clock 1 Mhz (factory default)
10
*********************************************/
10
*********************************************/
11
#include <avr/io.h>
11
#include <avr/io.h>
12
#include <inttypes.h>
12
#include <inttypes.h>
13
#define F_CPU 11059200UL  // 8 MHz
13
#define F_CPU 1000000UL  // 8 MHz
14
#include <util/delay.h>
14
#include <util/delay.h>
15
 
15
 
16
#define LED PINC5
16
#define LED PINC5
17
void cekej(int ms)
17
void cekej(int ms)
18
{
18
{
19
 
19
 
20
	// we use a calibrated macro. This is more
20
	// we use a calibrated macro. This is more
21
	// accurate and not so much compiler dependent
21
	// accurate and not so much compiler dependent
22
	// as self made code.
22
	// as self made code.
23
	while (ms)
23
	while (ms)
24
	{
24
	{
25
		_delay_ms(0.96);
25
		_delay_ms(0.96);
26
		ms--;
26
		ms--;
27
	}
27
	}
28
}
28
}
29
 
29
 
30
int main(void)
30
int main(void)
31
{
31
{
32
          /* INITIALIZE */
32
          /* INITIALIZE */
33
          /* enable PC5 as output */
33
          /* enable PC5 as output */
34
          DDRC|= (1<<LED);
34
          DDRC|= (1<<LED);
35
 
35
 
36
          /* PC5 is 5 (see file include/avr/iom8.h) and 1<<PC5 is 00100000 
36
          /* PC5 is 5 (see file include/avr/iom8.h) and 1<<PC5 is 00100000 
37
	   * This can also be written as _BV(PC5)*/
37
	   * This can also be written as _BV(PC5)*/
38
          while (1) {
38
          while (1) {
39
                      /* led on, pin=0 */
39
                      /* led on, pin=0 */
40
                      PORTC|= (1<<LED);
40
                      PORTC|= (1<<LED);
41
                      cekej(1000);
41
                      cekej(1000);
42
                      /* set output to 5V, LED off */
42
                      /* set output to 5V, LED off */
43
                      PORTC &= ~(1<<LED);
43
                      PORTC &= ~(1<<LED);
44
                      cekej(1000);
44
                      cekej(1000);
45
	}
45
	}
46
	  return(0);
46
	  return(0);
47
}
47
}