1019 views|1 replies

3183

Posts

0

Resources
The OP
 

I use eclipse programming in QUARTUS [Copy link]

Now I am learning eclipse programming in QUARTUS, and there are no problems with indicator lights and buttons.

So I want to write a program for HT1621.

Completely imitate the microcontroller.

The code is as follows:

#include  <stdio.h>					//标准的输入输出头文件
#include  "system.h"				//系统头文件
#include  "altera_avalon_pio_regs.h"//pio寄存器头文件
#include  "alt_types.h"				//数据类型头文件
#include  "sys/alt_irq.h"			//中断头文件
#include  "io.h"
#include "stdlib.h"

alt_u8  LED_Toggle = 0;				//LED状态切换全局变量
alt_u32 i=0;

alt_u8 DA;
alt_u8 WR;
alt_u8 CS;

#define Smg_a    0x80
#define Smg_b    0x40
#define Smg_c    0x20
#define Smg_d    0x01
#define Smg_e    0x02
#define Smg_f    0x08
#define Smg_g    0x04
#define Smg_dp   0x10

#define Bmp0Map          Smg_a | Smg_b | Smg_c | Smg_d | Smg_e | Smg_f
#define Bmp1Map          Smg_b | Smg_c
#define Bmp2Map          Smg_a | Smg_b | Smg_d | Smg_e | Smg_g
#define Bmp3Map          Smg_a | Smg_b | Smg_c | Smg_d | Smg_g
#define Bmp4Map          Smg_b | Smg_c | Smg_f | Smg_g
#define Bmp5Map          Smg_a | Smg_c | Smg_d | Smg_f | Smg_g
#define Bmp6Map          Smg_a | Smg_c | Smg_d | Smg_e | Smg_f | Smg_g
#define Bmp8Map          Smg_a | Smg_b | Smg_c | Smg_d | Smg_e | Smg_f | Smg_g
#define Bmp9Map          Smg_a | Smg_b | Smg_c | Smg_d | Smg_f | Smg_g
#define Bmp7Map          Smg_a | Smg_b | Smg_c
#define BmpAMap          Smg_a | Smg_b | Smg_c | Smg_e | Smg_f | Smg_g
#define BmpBMap          Smg_c | Smg_d | Smg_e | Smg_f | Smg_g
#define BmpCMap          Smg_a | Smg_d | Smg_e | Smg_f
#define BmpDMap          Smg_b | Smg_c | Smg_d | Smg_e | Smg_g
#define BmpEMap          Smg_a | Smg_d | Smg_e | Smg_f | Smg_g
#define BmpFMap          Smg_a | Smg_e | Smg_f | Smg_g




const unsigned char SegCode[] = {Bmp0Map,Bmp1Map,Bmp2Map,Bmp3Map,Bmp4Map,Bmp5Map,Bmp6Map,Bmp7Map,Bmp8Map,Bmp9Map,BmpAMap,BmpBMap,BmpCMap,BmpDMap,BmpEMap,BmpFMap};
unsigned char DpyNum[6] = {Smg_g,Smg_g,Smg_g,Smg_g,Smg_g,Smg_g}; //显示缓冲区



void delay(void)
{
	volatile alt_u16 i;
	for(i=0;i<20;i++);
}
void COMMAND_HT1621(unsigned char comm)
{
    //unsigned char i;
    CS=0;
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_CS_BASE, CS);
    delay();
    WR=0;
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE, WR);
    delay();
    for(i=0;i<3;i++)        //写命令
    {
        if((0x04<<i)&0x04)

			DA=1;    //100


        else
        	DA=0;
        IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_BASE, DA);
        delay();
        WR=0;
        IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE, WR);
        delay();
        WR=1;
        IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE, WR);
        delay();
    }
    for(i=0;i<9;i++)        //写命令数据
    {
        if((comm<<i)&0x80)  DA=1;    //100
        else                DA=0;
        IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_BASE, DA);
        delay();
        WR=0;
        IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE, WR);
        delay();
        WR=1;
        IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE, WR);
        delay();
    }
    CS=1;
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_CS_BASE, CS);
    delay();
}

void HT1621_Display(void)
{
    //unsigned char i;
    CS=0;                        //片选CS
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_CS_BASE, CS);
    delay();
    WR=0;
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE, WR);
    delay();
    for(i=0;i<3;i++)                   //写命令
    {
        if((0x05<<i)&0x04)  DA=1;
        else                DA=0;
        IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_BASE, DA);
        delay();
        WR=0;
        IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE, WR);
        delay();
        WR=1;
        IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE, WR);
        delay();
    }
    for(i=0;i<6;i++)                   //写地址
    {
        if((20<<i)&0x20)    DA=1;
        else                DA=0;
        IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_BASE, DA);
        delay();
        WR=0;
        IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE, WR);
        delay();
		WR=1;
		IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE, WR);
		delay();
    }
    for(i=0;i<8;i++)                   //写数据
    {
        if((DpyNum[5]<<i)&0x80)   DA=1;
        else                      DA=0;
        IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_BASE, DA);
        delay();
		WR=0;
		IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE, WR);
		delay();
		WR=1;
		IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE, WR);
		delay();
    }
    for(i=0;i<8;i++)                   //写数据
    {
        if((DpyNum[4]<<i)&0x80)   DA=1;
        else                      DA=0;
        IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_BASE, DA);
        delay();
		WR=0;
		IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE, WR);
		delay();
		WR=1;
		IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE, WR);
		delay();
    }
    for(i=0;i<8;i++)                   //写数据
    {
        if((DpyNum[3]<<i)&0x80)   DA=1;
        else                      DA=0;
        IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_BASE, DA);
        delay();
		WR=0;
		IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE, WR);
		delay();
		WR=1;
		IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE, WR);
		delay();
    }
    for(i=0;i<8;i++)                   //写数据
    {
        if((DpyNum[2]<<i)&0x80)   DA=1;
        else                      DA=0;
        IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_BASE, DA);
        delay();
		WR=0;
		IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE, WR);
		delay();
		WR=1;
		IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE, WR);
		delay();
    }
    for(i=0;i<8;i++)                   //写数据
    {
        if((DpyNum[1]<<i)&0x80)   DA=1;
        else                      DA=0;
        IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_BASE, DA);
        delay();
		WR=0;
		IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE, WR);
		delay();
		WR=1;
		IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE, WR);
		delay();
    }
    for(i=0;i<8;i++)                   //写数据
    {
        if((DpyNum[0]<<i)&0x80)   DA=1;
        else                      DA=0;
        IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_BASE, DA);
        delay();
		WR=0;
		IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE, WR);
		delay();
		WR=1;
		IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE, WR);
		delay();
    }
    CS=1;                          //释放CS
    IOWR_ALTERA_AVALON_PIO_SET_BITS(PIO_CS_BASE,CS);
    delay();
}

void LCD_Init(void)
{
    COMMAND_HT1621(0x01);         //SYS EN
    COMMAND_HT1621(0x03);         //LCD ON
    COMMAND_HT1621(0x29);         //4 COM  1/3 BIAS
    HT1621_Display();             //clear screen
}

//---------------------------------------------------------------------------
//-- 名称		:	main()
//-- 功能		:	程序入口
//-- 输入参数	:	无
//-- 输出参数	:	无
//---------------------------------------------------------------------------
int  main(void)
{
	/*FILE *fp=fopen("ccb.txt","a+");

	for(i=0;i<8;i++)
	{
		Data[i]=i;
		fprintf(fp,"%d\n",Data[i]);
	}
	for(i=0;i<8;i++)
	{

		fscanf(fp,"%d\n",&Data1[i]);
		printf("Data=%d\n0",Data1[i]);
	}*/
	printf("Code Running...");
	//Init_Interrupt();
	IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DA_BASE, 1);
	IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_WR_BASE, 1);
	IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_CS_BASE, 1);
	LCD_Init();
	DpyNum[0] = Smg_a|Smg_d|Smg_g;              //"三"
	DpyNum[1] = SegCode[1];
	DpyNum[2] = SegCode[3];
	DpyNum[3] = SegCode[5];
	DpyNum[4] = SegCode[7];
	DpyNum[5] = SegCode[9];

	HT1621_Display();               //刷新LCD


	while(1)
	{

		//LED_Toggle = ~LED_Toggle;
		//IOWR_ALTERA_AVALON_PIO_DATA(PIO_CS_BASE, LED_Toggle);
		/*IOWR_ALTERA_AVALON_PIO_CLEAR_BITS(PIO_CS_BASE,0);
		for(i=0;i<1000000;i++);
		IOWR_ALTERA_AVALON_PIO_SET_BITS(PIO_CS_BASE,1);
		for(i=0;i<1000000;i++);*/
		/*DpyNum[0] = Smg_a|Smg_d|Smg_g;              //"三"
		DpyNum[1] = SegCode[1];
		DpyNum[2] = SegCode[3];
		DpyNum[3] = SegCode[5];
		DpyNum[4] = SegCode[7];
		DpyNum[5] = SegCode[9];

		HT1621_Display();*/
	}

	return(0);
}

The result shows an error, as shown in the figure:

Could you please tell me where the problem might be? Thanks!

This post is from EE_FPGA Learning Park
Personal signature为江山踏坏了乌骓马,为社稷拉断了宝雕弓。
 

3183

Posts

0

Resources
2
 

Using a logic analyzer to capture a function shows the same data as the normal display of the microcontroller.
How strange.

This post is from EE_FPGA Learning Park
Personal signature为江山踏坏了乌骓马,为社稷拉断了宝雕弓。
 
 

Guess Your Favourite
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>
Featured Posts
Three steps to troubleshoot ADSL

As the most cost-effective and effective means of broadband access, ADSL has become a familiar term to netizens and has ...

Timing Counter T0 Timing Application Technology (Part 2)

1. Experimental tasks The AT89S51 timer/counter T0 generates a 2-second timer. When the 2-second timer comes, the indica ...

Using multipliers to realize triangle wave, square wave and sine wave generator

Using multipliers to realize triangle wave , square wave and sine wave generator

DIY RF Power Amplifier - Record the whole process

This post was last edited by RF-刘海石 on 2018-9-10 11:05 I haven't written a post here for a long time. I've been eithe ...

Use LGSR-WIFI serial port transparent transmission module as a remote external network online debugging tool to share

This post was last edited by cortex_M3 on 2020-8-2 19:35 Video first Video 1: LGSR-WIFI module WeChat network configur ...

[RVB2601 Creative Application Development] 5. OLED Displays Weather Information

1. Overview In the previous article, we have realized the acquisition of weather data and then printed it out through th ...

[Flower carving hands-on] Interesting and fun music visualization series of small projects (14) --- water cup and bottle lamp

I had the urge to do a series of topics on sound visualization. This topic is a bit difficult and covers a wide range of ...

[HPM-DIY] openmv for hpm6750 Progress 2 (face recognition 29fps+)

Openmv for hpm has been updated by the author in the past few days, mainly fixing the following: 644525 In addition, us ...

[Xingkong Board Python Programming Learning Main Control Board] Star Wars BB-8 Robot Controller Using Gyroscope and Voice Recognition

This post was last edited by HonestQiao on 2023-1-3 22:12 Table of contents: Zero, Introduction 1. Design Planning 2. S ...

AndroidBLE_osc_apply for permissions

The function of this software is to receive temperature data via Bluetooth and draw a temperature change curve. # 1. Get ...

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