技术热线: 4007-888-234

CCS初学流水灯程序+(Proteus)仿真

更新时间: 2019-03-26
阅读量:4174

/////////////////////////////////////////////////////////////////////////
////                             UTA_1.C                             ////
//// This program shows how to use the pins on a PIC16F630 for       ////
//// general I/O.When run, the program will run up and down the LEDs.////
////                                                                 ////
/////////////////////////////////////////////////////////////////////////
////               Copyright (C) 2006 www.czuta.com                  ////
//// Editor:   UltraEdit-32                                          ////
//// Compiler: CCS PCM C Compiler, Version 3.187                     ////

//// Programer:SUPERPRO 280                                          ////
//// Author:   LiuJian(cz_utb@126.com)                               ////
//// Data:     2006-02-08                                            ////
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
////                        Release Note                             ////
////  ROM used: 135 (13%)                                            ////
////  RAM used: 2 (3%) at main() level          ////

////            3 (5%) worst case                                    ////
/////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------//
// hardware.h
#ifndef _HARDWARE_H_
#define _HARDWARE_H_
#include <16F630.h>
/*Porta Define:
    RA0:     NOUSE    X
    RA1:     NOUSE    X
    RA2:     NOUSE    X
    RA3:     NOUSE    X
    RA4:     NOUSE    X
    RA5:     NOUSE    X
*/
#define TRISA_INIT     0x00
#define PORTA_INIT     0x00

/*Portc Define:
    RC0:     LED_1    OUT
    RC1:     LED_2    OUT
    RC2:     LED_3    OUT
    RC3:     LED_4    OUT
    RC4:     LED_5    OUT
    RC5:     NOUSE    X
*/
#define TRISC_INIT     0x00
#define PORTC_INIT     0x00

 

//Out Pin Marco Define
#define SET_LED_1  PIN_C0
#define SET_LED_2  PIN_C1
#define SET_LED_3  PIN_C2
#define SET_LED_4  PIN_C3
#define SET_LED_5  PIN_C4
// UTA_1.h
#define CYCLE_DEF  250      // CYCLE=1ms*CYCLE_DEF
#endif

//---------------------------------------------------------------------//
#fuses INTRC_IO,NOWDT,NOMCLR,NOPROTECT,NOCPD,BROWNOUT,PUT
#use delay(clock=4000000)
#use fast_io(A)
#use fast_io(C)
//---------------------------------------------------------------------//
void sfrinit(void)
{
//option
disable_interrupts(GLOBAL);
    set_tris_a(TRISA_INIT);
    output_a(PORTA_INIT);
    set_tris_c(TRISC_INIT);
    output_c(PORTC_INIT);
    setup_comparator(NC_NC_NC_NC);
}
//---------------------------------------------------------------------//

void userinit(void)
{
output_c(255);
delay_ms (CYCLE_DEF);
output_c(0);
delay_ms (CYCLE_DEF);

 

}
//---------------------------------------------------------------------//
void ledshow_forward (void)

{
output_low (SET_LED_5);
    output_high (SET_LED_1);
    delay_ms (CYCLE_DEF);
    output_low (SET_LED_1);
    output_high (SET_LED_2);
    delay_ms (CYCLE_DEF);
    output_low (SET_LED_2);
    output_high (SET_LED_3);
    delay_ms (CYCLE_DEF);
    output_low (SET_LED_3);
    output_high (SET_LED_4);
    delay_ms (CYCLE_DEF);
    output_low (SET_LED_4);
    output_high (SET_LED_5);
    delay_ms (CYCLE_DEF);
}
//---------------------------------------------------------------------//
void ledshow_backward (void)
{
    output_low (SET_LED_1);
    output_high (SET_LED_5);
    delay_ms (CYCLE_DEF);

{
output_low (SET_LED_5);
    output_high (SET_LED_1);
    delay_ms (CYCLE_DEF);
    output_low (SET_LED_1);
    output_high (SET_LED_2);
    delay_ms (CYCLE_DEF);
    output_low (SET_LED_2);
    output_high (SET_LED_3);
    delay_ms (CYCLE_DEF);
    output_low (SET_LED_3);
    output_high (SET_LED_4);
    delay_ms (CYCLE_DEF);
    output_low (SET_LED_4);
    output_high (SET_LED_5);
    delay_ms (CYCLE_DEF);
}
//---------------------------------------------------------------------//
void ledshow_backward (void)
{
    output_low (SET_LED_1);
    output_high (SET_LED_5);
    delay_ms (CYCLE_DEF);

  userinit();
    while(1)
    {
     ledshow_forward();
     ledshow_backward();
    }
}

 

//---------------------------------------------------------------------//