With your guyz help and being able to look at how the coding is suppose to look like by using CodeVisionAVR. I was able to understand the datasheet more and how to write the settings I wanted.
I have been able to get a program the builds without errors. My goal was to write a small lean program without unneeded bloat. I'm getting pretty close.
Here is what I have so far
/*
* 5-7 256 WDP 2s.c
* Author : rascal
*/
#define F_CPU 1000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <util/delay.h>
EMPTY_INTERRUPT(WDT_vect) //clearing the interrupt flag
int main(void)
{
cli(); // Disable global interrupts before initialization
CCP=0xD8; // Unlock protected register
CLKMSR=(0<<CLKMS1) | (1<<CLKMS0); // Change clock source to Low-power 128 kHz oscillator
CCP=0xd8;
CLKPSR=(1<<CLKPS3) | (0<<CLKPS2) | (0<<CLKPS1) | (0<<CLKPS0); // Clock division factor 256
PRR = (1<<PRTIM0); // Turn timer0 off
DDRB = 0b00001111; // Pins 1 - 3 - 5 - 6 outputs
//PUEB = (1<<PUEB3); // Enable Pull up Resistor Pin 6
ACSR = (1<<ACD); // Turn off Analog comparator
CCP=0xd8;
// Watch dog timer prescaler = 2.0s
WDTCSR=(1<<WDIF) | (1<<WDIE) | (0<<WDP3) | (0<<WDE) | (1<<WDP2) | (1<<WDP1) | (1<<WDP0);
VLMCSR=(0<<VLMF) | (0<<VLMIE) | (0<<VLM2) | (0<<VLM1) | (0<<VLM0); // Trigger Level: Voltage Level Monitor Disabled
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
sleep_enable();
wdt_reset(); // Watchdog reset
sei(); //initialize global interrupts before beginning loop
while (1) {
// Blink PB0 (Pin 1 RED led) 5 times then sleep
PORTB |=(1<<PB0); // 1 turn the LED on (HIGH is the voltage level
_delay_ms(250); // wait for 250ms
PORTB &=~(1<<PB0); // turn the LED off by making the voltage LOW
_delay_ms(150); // wait for 150ms
PORTB |=(1<<PB0); // 2 turn the LED on (HIGH is the voltage level
_delay_ms(250); // wait for 250ms
PORTB &=~(1<<PB0); // turn the LED off by making the voltage LOW
_delay_ms(150); // wait for 150ms
PORTB |=(1<<PB0); // 3 turn the LED on (HIGH is the voltage level
_delay_ms(250); // wait for 250ms
PORTB &=~(1<<PB0); // turn the LED off by making the voltage LOW
_delay_ms(150); // wait for 250ms
PORTB |=(1<<PB0); // 4 turn the LED on (HIGH is the voltage level
_delay_ms(250); // wait for 250ms
PORTB &=~(1<<PB0); // turn the LED off by making the voltage LOW
_delay_ms(150); // wait for 150ms
PORTB |=(1<<PB0); // 5 turn the LED on (HIGH is the voltage level
_delay_ms(250); // wait for 250ms
PORTB &=~(1<<PB0); // turn the LED off by making the voltage LOW
_delay_ms(150); // wait for 150ms
sleep_enable(); // sleep mode to extend the (pause) between blinking time
sleep_cpu();
// Blink PB0 (Pin 2 GREEN led) 7 times then sleep
PORTB |=(1<<PB1); // 1 turn the LED on (HIGH is the voltage level
_delay_ms(250); // wait for 250ms
PORTB &=~(1<<PB1); // turn the LED off by making the voltage LOW
_delay_ms(150); // wait for 150ms
PORTB |=(1<<PB1); // 2 turn the LED on (HIGH is the voltage level
_delay_ms(250); // wait for 250ms
PORTB &=~(1<<PB1); // turn the LED off by making the voltage LOW
_delay_ms(150); // wait for 150ms
PORTB |=(1<<PB1); // 3 turn the LED on (HIGH is the voltage level
_delay_ms(250); // wait for 250ms
PORTB &=~(1<<PB1); // turn the LED off by making the voltage LOW
_delay_ms(150); // wait for 150ms
PORTB |=(1<<PB1); // 4 turn the LED on (HIGH is the voltage level
_delay_ms(250); // wait for 250ms
PORTB &=~(1<<PB1); // turn the LED off by making the voltage LOW
_delay_ms(150); // wait for 150ms
PORTB |=(1<<PB1); // 5 turn the LED on (HIGH is the voltage level
_delay_ms(250); // wait for 250ms
PORTB &=~(1<<PB1); // turn the LED off by making the voltage LOW
_delay_ms(150); // wait for 150ms
PORTB |=(1<<PB1); // 6 turn the LED on (HIGH is the voltage level
_delay_ms(250); // wait for 250ms
PORTB &=~(1<<PB1); // turn the LED off by making the voltage LOW
_delay_ms(150); // wait for 150ms
PORTB |=(1<<PB1); // 7 turn the LED on (HIGH is the voltage level
_delay_ms(250); // wait for 250ms
PORTB &=~(1<<PB1); // turn the LED off by making the voltage LOW
_delay_ms(250); // wait for 250ms
sleep_enable(); // 2 sleep modes to extend the (pause) not blinking time
sleep_cpu();
sleep_enable(); // 2 sleep modes to extend the (pause) not blinking time
sleep_cpu();
}
// Watchdog Interrupt Service / is executed when watchdog timed out
ISR(WDT_vect);
}
Question. Since I'm using the WDT and not the main system clock, can I take this out ?
CLKPSR=(1<<CLKPS3) | (0<<CLKPS2) | (0<<CLKPS1) | (0<<CLKPS0); // Clock division factor 256
To me, it would seem unneeded. And I get error if I don't put a ; here
}
// Watchdog Interrupt Service / is executed when watchdog timed out
ISR(WDT_vect);
}
I see others not have the ;
One thing all this has taught me is that I magic powers.. The hex files generated are from 700 - 990 bytes but only write a little more than half of that to the chip and it works.
Also, I have been able to write to the chip at the highest speed no matter how slow the mcu is clocked at. I guess, since the mcu speed it set in the code, when the mcu is reset and written to, it defaults to the default speed.