要求:利用DA转化产生几种不同的波形,例如三角波,锯齿波等等

#include <reg52.h>
 #define uchar unsigned char 

 #define uint unsigned int 

 #define juchi 0 

 #define fangbo 1 

 #define sanjiao 2 

 #define zhengxian 3 



 uchar xdata DA_CS _at_ 0xA000;  

 uint i; 

 uchar tag; 

 void delay(int ms) 

 { 

     int i,j; 

     for(i = 0;i < 50;i++) 

           for(j = 0;j < 60;j++) 

           { 

            ; 

           } 

 } 

 void time0() interrupt 1 

 { 

     TH0=(65535-10000)/256; 

     TL0=(65535-10000)%256; 



     switch(tag){ 

         case juchi: 

             //锯齿 

             i++; 

             DA_CS=i; 

             break; 

         case fangbo: 

             i+=85; 

             if(i==255){ 

                 i=0; 

             } 

             DA_CS=i; 

             break; 

         case sanjiao: 

             for(i=0;i<254;i++){ 

                 DA_CS=i; 

                             //   if(i = 0x80)  delay(30); 

                                delay(1); 

             } 



             for(i=255;i>1;i--){ 

                 DA_CS=i; 

                             //     if(i = 0x80)  delay(30); 

                                 delay(1); 

                                  

             } 

             break; 

         case zhengxian: 

              

             break; 

     } 



 } 



 void main() 

 { 

     TMOD=0x01; 

     TR0=1; 

     IE=0x82; 

     TH0=(65535-10000)/256; 

     TL0=(65535-10000)%256; 

     i=0; 

     tag=sanjiao; 



     while(1); 

 }