| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 683 人关注过本帖
标题:c程序课程设计
只看楼主 加入收藏
ntcmk
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-6-4
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:7 
c程序课程设计
急求一个c程序课程设计?大家帮帮忙阿 大恩不言谢拉
急求一个c程序课程设计?大家帮帮忙阿 大恩不言
谢拉急求一个c程序课程设计?大家帮帮忙阿 大恩不言谢拉
搜索更多相关主题的帖子: c程序 设计 课程 
2012-06-04 15:39
angel丶诗
Rank: 2
等 级:论坛游民
帖 子:13
专家分:36
注 册:2012-6-2
收藏
得分:5 
前天刚做完的sopc课程设计 做的万年历 c编程  有些还是能用的 - -

头文件 LCD.h
#ifndef _LCD_H_
#define _LCD_H_
//LCD Module 16*2
#define lcd_write_cmd(base,data) IOWR(base,0,data)
#define lcd_read_cmd(base) IORD(base,1)
#define lcd_write_data(base,data) IOWR(base,2,data)
#define lcd_read_data(base) IORD(base,3)
//----------------------
void LCD_Init();
void LCD_Show_Text(char *Text);
void LCD_Line2();
void LCD_Test();
//---------------------------
#endif //_LCD_H_

程序 wnl.c

#include "alt_types.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "system.h"
#include "sys/alt_irq.h"
#include "altera_avalon_pio_regs.h"
//#include"count_binary.h"
#include "LCD.h"
#include "io.h"
volatile int edge_capture;

void LCD_Init()
{
  //LCD初始化
    lcd_write_cmd(LCD_BASE,0x38);
    usleep(2000);
    lcd_write_cmd(LCD_BASE,0x0C);
    usleep(2000);
    lcd_write_cmd(LCD_BASE,0x01);
    usleep(2000);
    lcd_write_cmd(LCD_BASE,0x06);
    usleep(2000);
    lcd_write_cmd(LCD_BASE,0x80);
    usleep(2000);
}
void LCD_Show_Text(char*Test)
{
  //LCD输出格式
  int i;
  for(i=0;i<strlen(Test);i++)
  {
    lcd_write_data(LCD_BASE,Test[i]);
    usleep(2000);
  }
}
void LCD_Line1()
{
  //向LCD写命令
  lcd_write_cmd(LCD_BASE,0x80);
  usleep(2000);
}
void LCD_Line2()
{
  lcd_write_cmd(LCD_BASE,0xC0);
  usleep(2000);
}

static void handle_button_interrupts(void*context,alt_u32 id)
{
    volatile int*edge_capture_ptr=(volatile int*)context;
   
    *edge_capture_ptr=IORD_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_BASE);
   
    IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_BASE,0);
}
  //按键初始化
static void init_button_pio()
{
  void *edge_capture_ptr=(void*)&edge_capture;

  IOWR_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_BASE,0xf);

  IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_BASE,0x0);

  alt_irq_register

(BUTTON_IRQ,edge_capture_ptr,handle_button_interrupts);
}
void delay(unsigned int x)
{
  while(x--);
}
int check_month(int month)
{
  if((month==1)||(month==3)||(month==5)||(month==7)
     ||(month==8)||(month==10)||(month==12))
     return 1;
  else if((month==4)||(month==6)||(month==9)||(month==11)) return 0;
  else //if(month==2)
    return 2;
}


int check_year(int year)
{
  if(((year%400)==0)||(((year%4)==0)&&((year%100)!=0))) return 1;
  //是闰年,返回1
  else return 0;
  //不是闰年,返回0
}
int main (void) __attribute__ ((weak, alias ("alt_main")));
int alt_main (void)
//int main(void)
{
    int screen=0; //共有两行,一行显示年月日,一行显示时间

    int pos=0;//每行都有三个位置,第一行是年月日,第二行是时分秒
    int year,month,day,hour,minute,second;
    unsigned long sum;
    char date[16];
    char time[16];
    int year1=1;
    int year2=1;
    int year3=0;
    int year4=2;
    int month1=6;
    int month2=0;
    int day1=8;
    int day2=1;
    int hour4,hour3,hour2,hour1,minute2,minute1,second2,second1;
    unsigned int screenflag;
    hour=0;minute=0;second=0;year=2011;month=6;day=18;
    //年月日时分秒初始化
    alt_irq_init(ALT_IRQ_BASE);
    init_button_pio();
    IOWR_ALTERA_AVALON_PIO_DATA(LCD_ON_BASE,1);
    LCD_Init();
    while(1)
    {
        if(pos>=3) pos=0;//共有三个位置0,1,2
        if(screen>=2) screen=0;
        //na_LED8->np_piodata=1<<pos;
        if(screen==0) screenflag=8;//用一个LED指示当前调整的位置
        else screenflag=0;
        IOWR_ALTERA_AVALON_PIO_DATA(LED_BASE,(1<<screen)|screenflag);
        usleep(1000000);//等待1秒的定时时间
        if(second<59) second++;
        else
        {
          second=0;
          if(minute<59) minute++;
          else
          {
            minute=0;
            if(hour<23) hour++;
            else
            {
              hour=0;
              if(day<30) day++;
              else
              {
                day=1;
                if (month<12) month++;
                else {
                  month=1;
                  if(year<9999) year++;
                  else year=2005;
                }
              }
          }
        }
      }
  switch (edge_capture) //检测按钮
  {
            case 0x08: pos=pos+1; break; //改变调整位置
            case 0x02:
                if (pos==0)
                {
                    if(screen==0)
                    {
                          if (day>1) day--;
                          else
                          {
                            if (check_month(month)==0) day=30;
                            if (check_month(month)==1) day=31;
                            if (check_month(month)==2)
                               {
                                  if(check_year(year))day=29;
                                  else day=28;
                                }
                         }
                    }
                    if (screen==1)
                       {
                          if(second>0) second--; else second=59;
                       }
                 }
                else if(pos==1)
                  {
                      if(screen==0)
                       {
                        if(month>1) month--; else month=12;
                       }
                     if(screen==1)
                       {
                        if(minute>0) minute--; else minute=59;
                       }
                  }
                 if(pos==2)
                  {
                      if(screen==0)
                        {
                           if (year>0) year--;
                           else year=2005;
                        }
                      if (screen==1)
                        {
                          if (hour>0) hour--;else hour=23;
                        }
                  }
               break;
            case 0x04:
               if (pos==0)
                 {
                    if (screen==0)
                    {
                        if(check_month(month)==0)
                          { if(day<30) day++;else day=1;}
                        else if (check_month(month)==1)
                          { if (day<3) day++;else day=1;}
                        else if(check_month(month)==2)
                          {
                            if (check_year(year))
                              { if(day<29) day++ ; else day=1;}
                            else { if (day<28) day++ ; else day=1;}
                          }
                    }
                    else if(screen==1)
                      {
                        if(second<59) second++; else second=0;
                      }
                 }
              else if (pos==1)
                {
                    if(screen==0)
                      {
                       if (month<12) month++; else month=1;
                      }
                  
                    else if(screen==1)
                      {
                       if (minute<59) minute++; else minute=0;
                      }
               }
            
              if(pos==2)
                {
                  if (screen==0)
                    {
                     if (year<9999) year++; else year=2005;
                    }
                  else if (screen==1)
                    {
                      if (hour<23) hour++; else hour=0;
                    }
                }
              break;
        case 0x01: screen++; break; //换屏
    }
edge_capture=0;
{

      year4=year/1000;
      year3=(year-year4*1000)/100;
      year2=(year-year4*1000-year3*100)/10;
      year1=year%10;
      month2=month/10;
      month1=month%10;
      day2=day/10;
      day1=day%10;
      LCD_Line1();
      date[0]=year4+0x30;date[1]=year3+0x30;
      date[2]=year2+0x30;date[3]=year1+0x30;
      date[4]=' '; date[5]=' ';
      date[6]=month2+0x30; date[7]=month1+0x30;
      date[8]=' ';date[9]=' ';
      date[10]=day2+0x30;date[11]=day1+0x30;
      date[12]=' '; date[13]=' ';
      date[14]=' ';date[15]=' ';
      LCD_Show_Text(date);

    hour4=0;hour3=0;
    hour2=hour/10;hour1=hour%10;
    minute2=minute/10;
    minute1=minute%10;
    second2=second/10;
    second1=second%10;
    time[0]=' ';time[1]=' ';
    time[2]=hour2+0x30;time[3]=hour1+0x30;
    time[4]=' ';time[5]=' ';
    time[6]=minute2+0x30;time[7]=minute1+0x30;
    time[8]=' ';time[9]=' ';
    time[10]=second2+0x30;time[11]=second1+0x30;
    time[12]=' ';time[13]=' ';
    time[14]=' ';time[15]=' ';
    LCD_Line2();
    LCD_Show_Text(time);
}

//将数据转换为显示器件可以接收的格式
  sum=year4*0x1000000+year3*0x1000000+year2*0x100000+year1*0x10000;
  sum=sum+month2*0x1000+month1*0x100+day2*0x10+day1;
//数据送显示器件(8个7段数码管)进行显 示
    //IOWR_ALTERA_AVALON_PIO_DATA(LCD_BASE,sum);
}
   
}
2012-06-04 20:19
真的很菜
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:94
专家分:151
注 册:2012-2-18
收藏
得分:5 
这论坛不是坚决不直接给代码求作业的吗?为何还有人给代码?
2012-06-05 00:53
ntcmk
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-6-4
收藏
得分:0 
回复 3楼 真的很菜
因为有好人嘛
2012-06-05 15:58
ntcmk
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-6-4
收藏
得分:0 
回复 2楼 angel丶诗
这个好像不怎么看得懂
2012-06-05 16:25
angel丶诗
Rank: 2
等 级:论坛游民
帖 子:13
专家分:36
注 册:2012-6-2
收藏
得分:0 
回复 5楼 ntcmk
- -  额· 那我也没办法·只是给个参考的
  中间那些判断平润年· 大小月 还有时分秒的进位的可以参考下
2012-06-05 22:27
ntcmk
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-6-4
收藏
得分:0 
回复 6楼 angel丶诗
  好吧 不过还是谢谢你啦
2012-06-05 22:29
ab1034982749
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:215
专家分:1185
注 册:2012-4-14
收藏
得分:5 
还是自己写吧!
2012-06-05 22:33
快速回复:c程序课程设计
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.039222 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved