⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 software LCD driver for microcontroller
💻 C
字号:
/*=============================================================================Cyan Technology LimitedFILE - main.cDESCRIPTION    Demonstrates direct drive software for a static LCD. Parallel and general	purpose IOs are initialised to drive a 4-digit 7-segment display, with	support for one backplane. The PIOs are updated at 64 Hz using timer	interrupt to generate a 32 Hz LCD frame rate. An elapsed minute/second	time counter, driven by a 1 Hz counter interrupt is used as a LCD	application example.MODIFICATION DETAILS=============================================================================*//******************************************************************************Project level include files.******************************************************************************/#include <ecog.h>#include <ecog1.h>#include <stdio.h>#include "driver_lib.h" /******************************************************************************Include files for public interfaces from other modules.******************************************************************************//******************************************************************************Declaration of public functions.******************************************************************************//******************************************************************************Private constants and types.******************************************************************************/#define BP_HIGH		0x10					// To drive backplane (GPIO17) high#define BP_LOW		0x20					// To drive backplane (GPIO17) low/******************************************************************************Declaration of static functions.******************************************************************************/// Called from irq service routinesvoid __irq_entry cnt1_handler (void);		// Update elapsed time countervoid __irq_entry tmr_handler (void);		// Drive LCD/******************************************************************************Global variables.******************************************************************************//******************************************************************************Module global variables.******************************************************************************/// Elapsed minute/sec time counter current valuestatic int clk_sec_lower = 0;static int clk_sec_upper = 0;static int clk_min_lower = 0;static int clk_min_upper = 0;/******************************************************************************Definition of API functions.******************************************************************************//******************************************************************************NAME    mainSYNOPSIS    int main(int argc, char * argv[])FUNCTION    Initialse the system and then go into sleep mode.RETURNS    Exit code.******************************************************************************/int main(int argc, char* argv[]){    // Select low frequency clock sources as timers clock source in configurator 		/* Initialise timer to generate a 64 Hz interrupt. Clock source is	 * the 32 kHz reference which is further divide down by 2^8 and 2.	 */	fd.ssm.rst_clr.tmr = 1;	fd.ssm.div_sel.tmr = 0;    fd.ssm.tap_sel3.tmr = 6;	fd.ssm.clk_en.tmr = 1;		rg.tim.tmr_ld = 1;    fd.tim.cmd.tmr_ld = 1;    fd.tim.ctrl_en.tmr_auto_re_ld = 1;    fd.tim.ctrl_en.tmr_cnt = 1;	fd.tim.int_en1.tmr_exp = 1;    	/* Initialise counter 1 to generate a 1 Hz interrupt in configurator.	 * Clock source is the 32 kHz reference which is further divide down	 * by 2^13 and 4.	 */		// Start counter 1 and enable interrupt    rg.tim.ctrl_en = TIM_CTRL_EN_CNT1_CNT_MASK;	rg.tim.int_en1 = TIM_INT_EN1_CNT1_EXP_MASK;	    /* Initialise PIOs as driven outputs in configurator:	 * Port L as PIOB 08-15 to drive LCD digit 1	 * Port K as PIOB 00-07 to drive LCD digit 2	 * Port F as PIOA 08-15 to drive LCD digit 3	 * Port E as PIOA 00-07 to drive LCD digit 4	 */		// Initialise Port I I2 to use GPIO17 for backplane output in configurator		// Disable unused peripheral clocks during sleep, and on wakeup in configurator	    // Set CPU clock to 16 kHz in configurator    	// Disable high ref oscillator and high pll to save power in configurator    rg.ssm.clk_dis = SSM_CLK_DIS_HIGH_OSC_MASK | SSM_CLK_DIS_HIGH_PLL_MASK;	    sleep();								// Put processor to sleep		//while(1);	    return 0;}/******************************************************************************Definition of Static Functions.******************************************************************************//******************************************************************************NAME    cnt1_handlerSYNOPSIS    void __irq_entry cnt1_handler(void)FUNCTION    Interrupt handler for counter 1 interrupt. Wakes up the processor every	1 second to increment the elapsed minute/second time counter.RETURNS    Nothing.******************************************************************************/void __irq_entry cnt1_handler (void){        fd.tim.int_clr1.cnt1_exp = 1;           // Clear the interrupt    	// Increment the elapsed time counter	clk_sec_lower++;	if (10 == clk_sec_lower)	{		clk_sec_lower = 0;		clk_sec_upper++;		if (6 == clk_sec_upper)		{			clk_sec_upper = 0;			clk_min_lower++;			if (10 == clk_min_lower)			{				clk_min_lower = 0;				clk_min_upper++;				if (6 == clk_min_upper)				{					clk_min_upper = 0;				}			}		}	}}/******************************************************************************NAME    tmr_handlerSYNOPSIS    void __irq_entry tmr_handler(void)FUNCTION    Interrupt handler for timer interrupt. Responsible for driving the LCD	segments via the PIOs and backplane via GPIO17. Initialised to run at	64 Hz to generate a 32 Hz LCD frame rate.RETURNS    Nothing.******************************************************************************/void __irq_entry tmr_handler (void){    static int pao, pbo;               		// Digit displays buffer	static int bp_sig;						// Backplane signal polarity	// Coded digit display	static int disp_clk_sec_lower;	static int disp_clk_sec_upper;	static int disp_clk_min_lower;	static int disp_clk_min_upper;		// 7-segment coded data for the number 0 to 9    const int seg_code[] = { 0x3f, 0x06, 0x5b, 0x4f, 0x66, 							 0x6d, 0x7d, 0x07, 0x7f, 0x67};        fd.tim.int_clr1.tmr_exp = 1;            // Clear the interrupt		// Update the LCD display    rg.io.pa_out = pao;    rg.io.pb_out = pbo;	rg.io.gp16_19_out = bp_sig;	    // Encode the next elapsed time counter value    disp_clk_sec_lower = seg_code[clk_sec_lower];	disp_clk_sec_upper = seg_code[clk_sec_upper];	disp_clk_min_lower = seg_code[clk_min_lower];	disp_clk_min_upper = seg_code[clk_min_upper];	disp_clk_min_upper += 0x80;				// Add colon		// Generate the next half of a LCD frame value    if (bp_sig == BP_HIGH)    {        bp_sig = BP_LOW;    				// Invert backplane for next update    }    else    {        bp_sig = BP_HIGH;    				// Invert backplane for next update        disp_clk_sec_lower ^= 0xff;			// Invert bits		disp_clk_sec_upper ^= 0xff;		disp_clk_min_lower ^= 0xff;		disp_clk_min_upper ^= 0xff;	}		// Fill the digit display buffers, ready for next update.	pao = (disp_clk_sec_upper << 8) + disp_clk_sec_lower;    pbo = (disp_clk_min_upper << 8) + disp_clk_min_lower;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -