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

📄 ksr810.c

📁 PIC单片机上用C语言写的TW88TFT屏控制程序,有注释
💻 C
📖 第 1 页 / 共 5 页
字号:
/**************************************************/
/*        KSR-810                                */
/*        -> auto-power_on                        */
/*        -> save in eeprom when power off        */ 
/*        -> off eeprom when no save              */ 
/*        main.c                                  */
/*        Main Program                            */
/*  Hinh Sary 25/08/2005                          */ 
/**************************************************/

#include <pic16f7x.h> // PIC16F73 register
#include <pic.h>  // use some assembler instructions

#include "function.h" // function declaration 
#include "TW88_reg.h" // TW8801 register    
#include "window_option.h"  // values of the windows options

//#pragma origin 4 // interrupt address

////////////////////////////////////////////////////
// Global Constants
 
// MPU<->DVD Player
#define CSI        RB2
#define CSO        RB3
#define MUTE       RC2
//#define VIDEO_AUX  RC3
#define DVDPOWER   RC4

// MPU<->EEPROM
#define EEPROM     0xA0 //bit0 = 0 (write), 1 (read)
#define EEPOWER    RC0  //eeprom supply 0:off  1:on 

// analog channel
#define BATTERY_PIN 2
#define KEY_PIN     4
#define REF_PIN     3
#define ALERTE1     224 //230 207 emule value 213
#define ALERTE2     216 //222 197 206 
#define BATTERY_REF 206 //212 180 199
#define BATTERY_ON_REF  148

// analog key reference 

#define POWER_REF   5
#define MODE_REF    70
#define UP_REF      150
#define DOWN_REF    215 
    
// Remote code
#define CUSTOM  0x01
#define STANDBY 0x14
#define MODE    0x5e
#define DOWN    0x06
#define UP      0x05
 
// MPU<->TW88
#define SCL      RC6                                                 
#define SDA      RC5
#define CFSDA    TRISC5
#define TWRESET  RC7
#define DATA_MAX 20 // table size (for serial multiple R/W)

// MPU<->LCD
#define INVERT   RB6

// Power output
#define POWER_ON RC3 // 0:off 1:on
#define SCREEN_ON RC2

// option chosen
#define NUM10_MAX 3 // number10 table size 
#define BAR_MAX   30 //bar table size

// Panel options
#define P_CLK     27 //27MHz

////////////////////////////////////////////////////
// Global Variables

//video format

unsigned char format = 0;
//unsigned char test = 0;
//unsigned char test2=0;

//picture direction
bit direction = 0;

//battery 
bit battery_off = 0; //1 : battery too weak


// key flag
bit down = 0;
bit power = 0;
bit mode = 0;
bit up = 0;

bit key_pressed = 0; //1 : key pressed
bit autofire = 0; //1 : key continue pressed
bit key_free = 0; // 0:key released, 1:key no released 

// Select mode Time
unsigned int chrono = 0;

// Mode pressed counter
unsigned char choix = 0;
bit change=0;

// save TW88 setting variables
unsigned char bght = 0xd0; //-48 
unsigned char ctst = 0x6C; //108
unsigned char color = 0xA0; //160

//remocon
unsigned char remokey=0;

//
unsigned int mode_counter=0;

//switch video variables
bit switch_mode = 0; //switch video input flag
unsigned int win2_time = 0; //display window2 time 
unsigned char video = VIDEO1;

// display variables
unsigned char cnt; // counter characters
unsigned char addstart; //window content start address in ram
unsigned char win_size; //characters number max in window
unsigned char font_op; //font option 

//convert number into ascii value table
//unsigned char number10[NUM10_MAX]; 
// [1]:sign '0':+ '1':-
// [2:4]:|value|, [0][5]:'"'start/stop text    

interrupt EventExt(void)
{
   /* //save register state
    asm("MOVWF 0x20");   //save W reg at 20h
    asm("MOVF 0x03,W");  //save STATUS at W
    asm("MOVWF 0x21");   //save STATUS at 21h
    asm("CLRF 0x03");    //clear STATUS
    asm("MOVF 0x0A,W");  //save PCLATH at W
    asm("MOVWF 0x22");   //save PCLATH at 22h
    asm("CLRF 0x0A");    //clear PCLATH
*/
    //interruption code
    if(INTF)
    {
        //TMR1IE=0;
        remokey = GetRemoCode();
        INTF = 0; //reset INTF
        
        //TMR1IE=1;
    }
    /*if(TMR1IF)
    {
        TMR1IF = 0; 
        chrono++;
    } */   
  /*  //restore register original state
    asm("MOVF 0x22,W");
    asm("MOVWF 0x0A");    //restore PCLATH
    asm("MOVF 0x21,W");
    asm("MOVWF 0x03");    //restore STATUS
    asm("MOVF 0x20,W");   //restore W
*/
}


void main(void)
{

  Boot();

while(1) //main loop : normal run
{
    CLRWDT();
    
    while(POWER_ON) //power_on loop 
    { 
        //CheckBattery();            
     
        VideoFormat();
        
         if(!key_free)
        {
            
            if(!key_pressed)
                GetKey();
            else
                AutoKey();
        }
        else
            GetNoKey();

                                
        if(power)
        {
        
            ClearKey();
            QuitMode();
            PowerDown();  
            CLRWDT();
            key_free = 1;             
            INTE = 1;
            break;
        }    
        
        if(switch_mode)
        {
            win2_time++;
          /*  if(VIDEO_AUX && DVDPOWER)
                if(CSI || (win2_time == 580))
                    DVDPOWER = 0;
          */
            if(win2_time > 1500)
                QuitSwitch();
        }     

        if(mode) // choose option (mode pressed)
        {
            ClearKey();
            choix++;
            if(change)
                SaveLCDSetting(); //save eeprom
            change=0;
            
            DisplayMode();
            chrono = 0;                    
            /* ResetTimer();
            TMR1IE = 1; //timer1 interrupt enable
            TMR1ON = 1; //Start timer*/
            CLRWDT();
        }
        else if(choix!=0) //timer is running=>Option mode
             {       
                 CLRWDT();
                
                 if(up) //Up option chosen 
                 {
                     ClearKey();
                     UpMode();
                     DisplayMode();
                     chrono = 0;                    
                     /*ResetTimer();
                     TMR1ON = 1;*/
                     CLRWDT();
                 }
                 else if(down) //Down option chosen
                     {
                         ClearKey();
                         DownMode();
                         DisplayMode();
                         chrono = 0;                      
                         /*ResetTimer();
                           TMR1ON = 1;*/
                           CLRWDT();
                     }    
                 
                 chrono++;
                 if(chrono>3000) //timer>5s
                     QuitMode();
             } //end of option mode 
        
    } //end of power_on loop
        
    while(!POWER_ON) //power_down loop 
    {    
        CLRWDT();
       
        /*if(battery_off)   
           power = CheckBattery();            
        else*/
        
            if(!key_free)
                 GetPower();
             else
                 GetNoKey(); 
           

            
           if(power)
           {
                WakeUp();
                ClearKey();
                key_free = 1;
                INTE=1; 
            }
       
                                    
    } //end of power_down loop
} //end main loop
 
    NOP();
}

/**************************************************/
/*        Function Definition                     */
/**************************************************/

////////////////////////////////////////////////////
//        Inititialisation  functions             //
////////////////////////////////////////////////////

/**************************************************/
/*        Boot                                    */
/*function : Initialize PIC16F73                  */
/*input : none                                    */
/*output : none                                   */ 
/**************************************************/
void Boot(void)
{
    Delay_10ms(5); //wait for stabilizing Voltage (50ms) 	
    InitRegister();
    Delay_10ms(30); 
    WakeUp();    // auto_power on
}


/**************************************************/
/*        Delay_10ms                              */
/*function :  wait number*10ms                    */
/*input : unsigned int nb                         */
/*output : none                                   */ 
/**************************************************/
void Delay_10ms(unsigned int nb)
{
    unsigned int counter, counter10ms ,adjust; 
    adjust = 551;
     
    for(counter10ms=0;counter10ms<nb;counter10ms++)
        for(counter=0;counter<adjust;counter++)
            CLRWDT(); 
}

/**************************************************/
/*        InitRegister                            */
/*function : initialize PIC16F73 registers        */
/*input : none                                    */
/*output : none                                   */ 
/**************************************************/
void InitRegister(void)
{
  // PORTA, PORTB, PORTC :       
  // See electric Diagram for I/O
  
    PCON = 0x03;
 
    // PORTA : Configure RA0, RA1, RA2, RA5   
    // as analog inputs. RA4 : I/O or Counter 
    // V0DD=Vref => PCFG2:PCFG0=000 (p84)      
    TRISA  = 0x3f;
    PORTA  = 0x00;        
    ADCON1 = 0x00; 
  
    // PORTB     
                  //B7 B6 B5 B4 B3 B2 B1 B0
    TRISB = 0xb7; // 1  0  1  1  0  1  1  1 
    PORTB = 0x01; //RB6, Rb3, Rb2 (output) actif high level
                 //Rb0 (input) actif low  

    // PORTC      
                  //B7 B6 B5 B4 B3 B2 B1 B0	  
    TRISC = 0x00; // 0  0  0  0  0  0  0  0
    PORTC = 0xE0; //RC0 = 0 :eeprom off
                  //RC2 (mute) : active low     
                  //RC1=1 : Power on TW8801
                  //RC5, RC6 : Serial bus no use
                  //RC7=1 : TW8801 disabled (reset) 
    // AD interrupt (p21-23)
    ADIE = 0; // !!!Disables ADIE!!!
    ADIF = 0; // clear AD flag
    
    // remocon
    INTEDG = 0; //interrupt on falling edge
    INTE = 1;
    RBIF = 0;
    
    // Timer1
    T1CON = 0x30; //prescaler 1:8, fosc=1Mhz
                  //TMR1 reset cycle = 0,525s
    TMR1IE = 0; //timer1 interrupt disable
     
    //enable interrupt
    PEIE = 1; 
    GIE  = 1;
}

/**************************************************/
/*        ResetTW88                               */
/*function : Reset TW8801 registers               */
/*input : none                                    */
/*output : none                                   */ 
/**************************************************/
void ResetTW88(void)
{
    TWRESET = 0;   
    Delay_10ms(1);
    TWRESET = 1;
    //Delay_10ms(1);
}

/**************************************************/
/*        InitTW88                                */
/*function : initialize TW88 registers            */
/*input : none                                    */
/*output : none                                   */ 
/**************************************************/
void InitTW88(void)
{
   //initialize panel power
   InitLCDPower();
   BOOT_SHARP();

   format = 0x0F; 
          
   InitWindow1();
   InitWindow2();
   InitWindow3();
   InitWindow4();
}

/**************************************************/
/*        InitTable                               */
/*function : Init table (=0)                      */
/*input : unsigned char *data, unsigned char size */
/*output : none                                   */ 
/**************************************************/
void InitTable(unsigned char *data, unsigned char size)
{
    unsigned char i;

    for(i=0;i<size;i++)
        data[i] = 0; 
}

/**************************************************/
/*        VideoFormat                             */
/*function : detect video format and initialize   */
/*           TW88 register                        */
/*input : none                                    */
/*output : none                                   */ 

⌨️ 快捷键说明

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