Big_Smoke
Big_Smoke

Reputation: 57

How do I produce a sawtooth waveform using c language?

This is my program with regards to DAC using PIC18F97J60. I am new to this and already struggling alot so please do not judge me.

#include <P18F97J60.h>
//#include <delays.h>
//#include "delays.c"

void SPI1init(void);
void SPI1out(char Code);

void SPI1init(void)
{
    SSP1CON1 = 0b00100010;  // Enable SPI, CKP=0, Master, Fosc/64
    SSP1STATbits.CKE = 1;   // CKE=1, (rising edge for shift register)
    TRISCbits.TRISC3 = 0;   // RC3 is SCk
    TRISCbits.TRISC5 = 0;   // RC5 is SDO
    SPI1out(0x00);
}

void SPI1out(char Code)
{
    SSP1BUF = Code;         // Transmit
    while(SSP1STATbits.BF==0);  // Wait for END (Receipt Buffer Full)
    Code = SSP1BUF;         // Just read to clear BF
}

Diagram for the circuit: https://ibb.co/M1cChNB

Question of the assignment: https://ibb.co/rwz3kwP

Upvotes: 1

Views: 227

Answers (0)

Related Questions