Here is the code to generate a triangular wave of 8 bit resolution
1: void main()
2: {
3: unsigned char i;
4: while(1)
5: {
6: for(i=0;i<0xff;i++)
7: { /* Generate rising edge */
8: delay_ us(1);
9: PORTB= i; //data output to port B
10: }
11: for(i=0xfe;i>0x00;i--)
12: {/* Generate falling edge */
13: delay_ us(1);
14: PORTB = i; //data output to port B
15: }
16: }
17: }
You can directly give the output to any port in which DAC is connected or you can use it for internal reference also.
This can be used to generate triangular wave in any microcontroller like AVR, 8051, PIC, ARM.
And triangular waves are also essential in doing modulation.