Professional Documents
Culture Documents
#include <c8051f340.h>
#define SYSCLK 12000000 // Internal oscillator frequency in Hz
Sine Wave
#include "c8051F340.h"
unsigned char x[];
int i;
x[13]={128,192,238,255,238,192,128,64,17,0,17,64,128);
int main(void)
{
XBR1 = 0x40;
P4MDOUT=0xFF;
while(1)
{
for(i=0;i<12;i++)
{
P4=x[i];
}
}
}
Triangular wave:
#include "c8051F340.h"
main()
{
int i;
XBR1 = 0x40; //Enable crossbar P4MDOUT=0xFF; // All data lines Output
while (1)
{
P4 = i;
}
}
Square Wave
#include "c8051F340.h"
for(j=0;j<100;j++);
main
{
XBR10x40; //Enable crossbar P4MDOUT=0xFF;
P4= 0x00; // All data lines Output
while (1)
{
P4= 0x00;
DELAY_ms(10);
P4=0xFF;
DELAY ms(10);
//P4 = ~P4;
DELAY_ms(10);
}
}