3286 views|5 replies

931

Posts

3

Resources
The OP
 

【CH579M-R1】+ Turn on timer 0 to control LED flashing and refresh LCD time display [Copy link]

 

In order to refresh the date and time displayed on the LCD at regular intervals, I started to use the SysTick timer to count, but I didn't know where the interrupt processing function was after searching for a long time. I only found a function in the CH57x_sys.c file to get the current count value of SysTick. I looked through the data sheet but still had no clue. I had to set timer 0, set the interrupt cycle to 100ms, then add 1 to the timing variable in the interrupt processing function, and make judgments in the main loop of the main function. The following figure shows the test process:

The LED on the left of the upper left corner is a breathing light, and the LED on the right flashes at a cycle of 1 second. Here is the animated effect:

Here is the code for the test:

/********************************** (C) COPYRIGHT *******************************
* File Name          : Main.c
* Author             : WCH
* Version            : 
* Date               : 2020/09/10
* Description 		 : 开发板测试
*******************************************************************************/

#include "CH57x_common.h"
#include "lcd_5110.h"
#include "ds1307.h"


UINT8 TxBuff[]="This is a tx exam\r\n";
UINT8 RxBuff[100];
UINT8 trigB;
UINT8 mode;
uint16_t year;              //年
uint8_t week,month,day,hour,minute,second,DS_Buff[8];//月日时分秒
volatile UINT16 time,ms;

int main()
{
    UINT8 i,dir,half,flag;
    
    
/* 配置串口1:先配置IO口模式,再配置串口 */   
    GPIOA_SetBits(GPIO_Pin_9);
    GPIOA_ModeCfg(GPIO_Pin_8, GPIO_ModeIN_PU);			  // RXD-配置上拉输入
    GPIOA_ModeCfg(GPIO_Pin_9, GPIO_ModeOut_PP_5mA);		// TXD-配置推挽输出,注意先让IO口输出高电平
    UART1_DefInit();
    
// 测试串口发送字符串
    UART1_SendString( TxBuff, sizeof(TxBuff) );

// 配置定时器0
    TMR0_TimerInit( FREQ_SYS/10 );                  // 设置定时时间 100ms
    TMR0_ITCfg(ENABLE, TMR0_3_IT_CYC_END);          // 开启中断
    NVIC_EnableIRQ( TMR0_IRQn );

/* 配置LED和PWM */
    GPIOA_ModeCfg(GPIO_Pin_6, GPIO_ModeOut_PP_5mA); // PA6 - PWM4(LED4)
    GPIOB_ModeCfg(GPIO_Pin_6, GPIO_ModeOut_PP_5mA); // PB6 - LED3
    PWMX_CLKCfg( 4 );
    PWMX_CycleCfg( PWMX_Cycle_64 );
	

    GPIOB_ModeCfg(GPIO_Pin_4, GPIO_ModeOut_PP_5mA); // PB4 - LED_G
    GPIOB_ModeCfg(GPIO_Pin_7, GPIO_ModeOut_PP_5mA); // PB7 - LED_Y
    GPIOB_InverseBits(4);

    LCD_init();           //LCD5110初始化
	display_main();       //显示主界面
	
	DS1307_Init();        //初始化DS1307模块
	DS1307_read_date();
	
	
    // 中断方式:接收数据后发送出去
    UART1_ByteTrigCfg( UART_7BYTE_TRIG );
    trigB = 7;
    UART1_INTCfg( ENABLE, RB_IER_RECV_RDY|RB_IER_LINE_STAT );
    NVIC_EnableIRQ( UART1_IRQn );


    while(1)
    {
/*        //串口测试  查询方式:接收数据后发送出去
        len = UART1_RecvString(RxBuff);
        if( len )
        {
            UART1_SendString( RxBuff, len );            
        }
*/
		//PWM测试
        if(dir){
            i--;
            if(i == 0){
                dir = 0;
			    GPIOB_InverseBits(GPIO_Pin_4);
			}
        }
        else{
            i++;
            if(i == 64){
                dir = 1;
				GPIOB_InverseBits(GPIO_Pin_7);
			}
		}
        PWMX_ACTOUT( CH_PWM4, i, Low_Level, ENABLE);

//        PWMX_ACTOUT( CH_PWM7, 64-i, Low_Level, ENABLE);
        mDelaymS(10);
        //LED3闪烁测试
        time++;
        if(ms > 4){            //半秒处理
            ms = 0;
            GPIOB_InverseBits(GPIO_Pin_6);
            half++;
        }
		if(half>1){            //秒处理
		    second++;
			if(second > 59){
			    second = 0;
				DS1307_read_date();
			}
			display_time(hour,minute,second);
			half = 0;
			if(flag)           //轮换显示月日或年份
			    display_year(year);
			else
				display_date(month,day);
			flag++;
			if(flag > 1)
				flag = 0;
		}
    }
}


void UART1_IRQHandler(void)
{
    UINT8 i;
    
    switch( UART1_GetITFlag() )
    {
        case UART_II_LINE_STAT:        // 线路状态错误
            UART1_GetLinSTA();
            break;
        
        case UART_II_RECV_RDY:          // 数据达到设置触发点
            for(i=0; i!=trigB; i++)
            {
                RxBuff[i] = UART1_RecvByte();
                UART1_SendByte(RxBuff[i]);
            }
            break;
        
        case UART_II_RECV_TOUT:         // 接收超时,暂时一帧数据接收完成
            i = UART1_RecvString(RxBuff);
            UART1_SendString( RxBuff, i ); 
            break;
        
        case UART_II_THR_EMPTY:         // 发送缓存区空,可继续发送
            break;
        
        case UART_II_MODEM_CHG:         // 只支持串口0
            break;
        
        default:
            break;
    }
}

void TMR0_IRQHandler( void )        // TMR0 定时中断
{
    if( TMR0_GetITFlag( TMR0_3_IT_CYC_END ) )
    {
        TMR0_ClearITFlag( TMR0_3_IT_CYC_END );      // 清除中断标志
        GPIOB_InverseBits( GPIO_Pin_3 );        
    }
	ms++;
}

This post is from Domestic Chip Exchange

Latest reply

Qinheng CH579M-R1 Development Board Review Summary post: https://en.eeworld.com/bbs/thread-1140005-1-1.html   Details Published on 2020-9-21 11:12
 
 

1w

Posts

204

Resources
From 6
 

Qinheng CH579M-R1 Development Board Review

Summary post: https://en.eeworld.com/bbs/thread-1140005-1-1.html

This post is from Domestic Chip Exchange
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle
Personal signature

玩板看这里:

http://en.eeworld.com/bbs/elecplay.html

EEWorld测评频道众多好板等你来玩,还可以来频道许愿树许愿说说你想要玩的板子,我们都在努力为大家实现!

 
 
 

7422

Posts

2

Resources
2
 

It should be in .S or the corresponding .C, you need to fill it in yourself/

This post is from Domestic Chip Exchange

Comments

Should I add the name of the SysTick interrupt handler function to this file? [attachimg]500812[/attachimg]  Details Published on 2020-9-15 07:49
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

931

Posts

3

Resources
3
 
freebsder posted on 2020-9-14 21:32 It should be in .S or the corresponding .C, you need to fill it in yourself/

Do I need to add the name of the SysTick interrupt handler function to this file?

This post is from Domestic Chip Exchange

Comments

It doesn't have to be filled in here. Anyway, cortex supports linking of C code, so just put it in other C files. You can find the function name in this file. For example, the name of the film I have is SysTick_Handler .align 1 .thumb_func .weak ...  Details Published on 2020-9-15 11:03
 
 
 

7422

Posts

2

Resources
4
 
hujj posted on 2020-9-15 07:49 Should I add the name of the SysTick interrupt handler function to this file?

It doesn't have to be filled in here. Anyway, cortex supports linking C code, so just put it in other C files. You can find the function name in this file. For example, the name of the film I have is SysTick_Handler

    .align 1
    .thumb_func
    .weak SysTick_Handler
    .type SysTick_Handler, %function
SysTick_Handler:
    ldr   r0,=SysTick_Handler
    bx    r0
    .size SysTick_Handler, . - SysTick_Handler

In other C

viod SysTick_Handler(void)
{
    i++;
}

That's it.

Of course, don't forget to turn on systick, it is in the cmsis code, just call it directly.

This post is from Domestic Chip Exchange

Comments

Thank you! I found the SysTick_Handler content in the startup_ARMCM0.s file, as shown below: [attachimg]500941[/attachimg] Next, try to enable SysTick.  Details Published on 2020-9-15 18:30
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

931

Posts

3

Resources
5
 
freebsder posted on 2020-9-15 11:03 It doesn't have to be filled in here. Anyway, cortex supports linking C code, so just put it in other C files. Just the function name you can put in this file...

Thank you! I found the SysTick_Handler content in the startup_ARMCM0.s file, as shown below:

Next try how to enable SysTick.

This post is from Domestic Chip Exchange
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list