74 lines
1.2 KiB
C
74 lines
1.2 KiB
C
|
#include <reg52.h>
|
|||
|
#include <intrins.h>
|
|||
|
#include "delay.h"
|
|||
|
#include "main.h"
|
|||
|
#include "display.h"
|
|||
|
|
|||
|
|
|||
|
void fresh_wave();
|
|||
|
|
|||
|
unsigned char digital=0;
|
|||
|
unsigned char fresh_flag=0;
|
|||
|
|
|||
|
#ifdef MODE_1
|
|||
|
void fresh_wave()
|
|||
|
{
|
|||
|
digital++;
|
|||
|
P1=digital;
|
|||
|
}
|
|||
|
#endif
|
|||
|
#ifdef MODE_2
|
|||
|
unsigned char add_flag=0;
|
|||
|
void fresh_wave()
|
|||
|
{
|
|||
|
if(!add_flag)
|
|||
|
digital++;
|
|||
|
else
|
|||
|
digital--;
|
|||
|
if(digital==0&&add_flag)
|
|||
|
add_flag=0;
|
|||
|
else if(digital==255&&(!add_flag))
|
|||
|
add_flag=1;
|
|||
|
P1=digital;
|
|||
|
}
|
|||
|
#endif
|
|||
|
#ifdef MODE_3
|
|||
|
const unsigned char sine_var[]={128,136,143,151,159,167,174,182,189,196,202,209,215,220,226,231,235,239,243,246,249,251,253,254,255,255,255,254,253,251,249,246,243,239,235,231,226,220,215,209,202,196,189,182,174,167,159,151,143,136,128,119,112,104,96,88,81,73,66,59,53,46,40,35,29,24,20,16,12,9,6,4,2,1,0,0,0,1,2,4,6,9,12,16,20,24,29,35,40,46,53,59,66,73,81,88,96,104,112,119};
|
|||
|
void fresh_wave()
|
|||
|
{
|
|||
|
digital=sine_var[count%100];
|
|||
|
P1=digital;
|
|||
|
}
|
|||
|
#endif
|
|||
|
|
|||
|
|
|||
|
void time() interrupt 1
|
|||
|
{
|
|||
|
|
|||
|
TH0 = TH;
|
|||
|
TL0 = TL+15;
|
|||
|
fresh_flag=1;
|
|||
|
#ifdef MODE_3
|
|||
|
count++;
|
|||
|
#endif
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
int main()
|
|||
|
{
|
|||
|
//P1 <20><>
|
|||
|
setConfig();
|
|||
|
while(1)
|
|||
|
{
|
|||
|
if(fresh_flag==1)
|
|||
|
{
|
|||
|
fresh_flag=0;
|
|||
|
fresh_wave();
|
|||
|
set_display(digital);
|
|||
|
}
|
|||
|
#ifndef MODE_3
|
|||
|
fresh_display();
|
|||
|
#endif
|
|||
|
}
|
|||
|
}
|