/*
NOOB CODE
void setup() {
// put your setup code here, to run once:
char *portf_dir;
//This can work depending on the compiler and its settings.
//However, it’s not strictly standards-compliant because the address should be explicitly cast to a pointer type.
portf_dir = 0x30; //better to write (char *)0x30;
*portf_dir = 0xFF;
}
void loop() {
//The volatile keyword ensures that each access to portf_data actually reads from or writes to the hardware register, preventing the compiler from optimizing away these accesses.
volatile char *portf_data; //without volatile the LED will not glow because
// the compiler optimizes the value of *portf_dir and then it does not change to FF.
portf_data = 0x31;
*portf_data = 0x01;
}
*/
//BETTER CODE
#include "function.h"
void setup() {
// put your setup code here, to run once:
init_port();
}
void loop() {
//1. led on
char x;
x = 255; // x = 0b11111111; // x = 0xff;
output(x);
//2. blinking led
volatile long i;
for(i=0; i<1000000; i++)
x = 0; //command all led off
output(x); //set command
for(i=0; i<1000000; i++)
x = 255; // command all led on
output(x); // set command
//3. top-bottom-top led sequence
//top-bottom blink
for(x=0;x<8;x++)
{
output((1 << x));
for(i=0;i<1000000;i++);
}
//bottom-top
for(x=7;x>=0;x--)
{
output((1 << x));
for(i=0;i<1000000;i++);
}
}