Design of waveform generator based on tc1

Publisher:Delightful789Latest update time:2016-10-25 Source: eefocusKeywords:tc1 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
//***************FileName:Compare.C***************//

//***************ICCAVR V6.30 compiled*****************//

#include                  
#define uchar unsigned char
#define uint unsigned int

//Digital tube font table, corresponding to 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 //
uchar Table[10]={0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
uchar Data[4]={0,0,0,1}; //Define the initial square wave frequency: 1KHz
uchar Key1_Flag, Key2_Flag, Key3_Flag;

void DelayMs(uint i) //Ms level delay, parameter i is the delay time
{uint j;
for(;i!=0;i--)
{for(j=8000;j!=0;j--) {;}}
}

void Display(uchar *p) //dynamic display function, parameter p is the name of the array to be displayed
{uchar i,sel=0x01;           
for(i=0;i<4;i++)
{PORTA=sel; //select the rightmost digital tubePORTC
   =0xff-Table[p[i]]; //send font code
   DelayMs(1); //display delay    
   sel=sel<<1; //shift to display the previous digit
}
}

void Key_Process(uchar *p)
{uchar i,j,k;
while((PINB&0x01)==0) {Display(Da ta);Key1_Flag=1;} //Processing frequency hundreds, up to 5
while((PINB&0x02)==0) {Display(Da ta);Key2_Flag=1;}
while((PINB&0x04)==0) {Display(Da ta);Key3_Flag=1;}
if(Key1_Flag==1)
   {p[3]++;
if(p[3]==10) p[3]=0;
Key1_Flag=0;}   
if(Key2_Flag==1) //Processing frequency tens, up to 9
    {p[2]++;
if(p[2]==10) p[2]=0;
Key2_Flag=0;}
if(Key3_Flag==1) //Processing frequency every digit, up to 9
    {p[1]++;
if(p[1]==10) p[1]=0;
Key3_Flag=0;}
}

void Set_Process(void)
{uint i,j;
i=Data[0]*1000+Data[1]*100+Data[2]*10+Data[3];
j=500/i;
OCR1AH=j>>8;
OCR1AL=j&0x00ff;
}

void Init_IO(void) //Initialize I/O port
{DDRA=0xff; //Set port A to push-pull 1 output
PORTA=0xff;
DDRC=0xff; //Set port C to push-pull 1 output             
PORTC=0xff;
DDRB=0x00; //Set port B to tri-state input
PORTB=0x00;
DDRD=0xff; //Set port D to push-pull 1 output
PORTD=0xff;    
}

void Init_Timer1(void) //Initialize the input capture interrupt of T/C1
{TIMSK=TIMSK|0x10; //Output compare enable
TCCR1B=0x0a; //Clock 1 frequency, output compare match clear timer value
TCNT1H=0x00; //Clear timer value
TCNT1L=0x00;
Set_Process(); //OCR1A,OCR1B initial value
SREG=SREG|0x80; //Global disconnect
}

void main(void)
{Init_IO(); //Initialize I/O port
PORTA=0xff; //Light up to test all digital tubes
PORTC=0x00;   
Init_Timer1();                
DelayMs(300); //Delay
PORTC=0xff; //Turn off all digital tubes
while(1)
{Key_Process( Data);
Set_Process();
Display( Data); //Dynamic scan display
}
}

#pragma interrupt_handler Compare:7
void Compare(void)
{PORTD=~PORTD;}

Keywords:tc1 Reference address:Design of waveform generator based on tc1

Previous article:Design of frequency meter based on tc1
Next article:Clock design based on tc0

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号