/* short program to set pwm to a value from command line
    For initialising the CPU hardware, refer to inithard.c.
there are also fine motor controls for this kind of pulses */
#include <asm/MC68EZ328.h> 

#include <stdio.h>
#include <asm/delay.h>
#define PWMS_R 0xfffff503     /* lower byte of sampling register */
void set_pwm(unsigned char value)
{
    (*(volatile unsigned char *)PWMS_R) = value ; /* populate sample with data */
}

int main(int argc, char *argv[])
{
unsigned int val;
unsigned char out;
switch (argc) {
    case 2:	sscanf(argv[1], "%d",&val);
		if (val > 255) val = 255;
		if (val < 0) val = 0;
		set_pwm(val);
		break;
    case 1:	out = (*(volatile unsigned char *)PWMS_R);
		printf("PWM: %d\n",out);
		break;
    default : 	printf("Sets/Reads PWM for MC68EZ328. usage: setpwm [value]\n");
		break;
	}
exit(0);
}
