Fly Sikar mc9s12xs128 function module driver

Source: Internet
Author: User

It has been used for more than a year as the processor, and now summarizes the drivers of various functional modules.

// The bus frequency of the Phase-Locked Loop clock Initialization is 40 MHz (half of the Phase-Locked Loop clock)
// 11.0592 MHz Crystal Oscillator
Void pll_init (void) // pllclk = 2 * oscclk * (synr + 1)/(refdv + 1)
{// Phase-Locked Loop clock = 2*11.0592*(39 + 1)/(10 + 1) = 80 MHz bus clock is 40 MHz
Refdv = 0x0a;
Synr = 0x67; // The value of the 0110_0111 low 6 bits is 19, and the value of the high bits is the recommended value.

While (crgflg_lock! = 1 );
Clksel_pllsel = 1; // select the PLL clock
// Fclkdiv = 0x0f; // flash clock divide factor 16 m/16 = 1 m
}

 

// Initialize the periodical interrupt timer-
/// Periodic interrupt Channel 1 is used for timing sampling of the pulse accumulators. the scheduled period is 10 Ms = (199 + 1) * (1999 + 1)/(40 m) (not used)
// The periodic interrupt channel 0 is used to control the rotation of the laser tube. The scheduled cycle is 2000us = (399 + 1) * (199 + 1)/(40 m)
// Change the scheduled time to 1 ms on

Void pit_init (void)
{
Pitcflmt_pite = 0; // do not use the pit module pitcflmt: pit control to forcibly load the microcounter register.
Pitce_pce0 = 1; // enable timer channel 0
// Pitce_pce1 = 1; // enable timer Channel 1
Pitmux = 0; // channel 0, and channel 1 both Select 8-bit Micro counter 0

// Modify the following four rows for the modification time:
Pitmtld0 = 199; // The value loaded to the eight-bit counter
Pitld0 = 199; // value loaded to the 16-bit counter
// Pitmtld1 = 39; // The value loaded to the eight-bit counter is 8 bits, and the maximum value cannot exceed 255.
// Pitld1 = 1999; // value loaded to the 16-bit counter

Pitinte | = 0x01; // enable the timer to interrupt the channel 0
Pitcflmt_pite = 1; // enable the pit Module
}

 

// Pulse accumulators initialization, pT7 external Photoelectric Encoder
// Latest modification:
Void pt7_pulacc_init (void)
{
Ddrt & = 0x77; // set pT7 and pt3 port as input (pT7 and pt3 are connected to one part by Jumper)
PERT | = 0x80; // enables the uplink resistance of Channel 7.
Ppst & = 0x7f; // The resistance is set to the pull-up resistance.
Tctl4 & = 0x3f; // disable the input capture function of pt3
Pactl = 0x50; // start the pulse accumulation counter, trigger the rising edge, disable triggering the interrupt and overflow interruption, and disable the main timer.
}

 

// Channel 1 is used to control the steering gear 1 PWM High level,
// Channel 3 is used to control the low PWM of motor 1, which is different from that of the previous two generations !!!!!
// Channel 7 is used to provide a PWM signal for the upper laser tube. The PWM signal is valid at a high level !!!!!
// Channel 6 is used to provide the PWM signal for the lower-line laser tube. The PWM signal is valid at a high level !!!!!
// Added the use of port A to add Channel 6
// Added the combined use of Channel 4 and 5, used to control the lower direction Steering Gear
Void pwm_init (void)
{
Pwme = 0x00; // PWM disabled

Pwmprclk = 0x03; // clocka = 40 m/8 = 5 m, clock B = 40 m/1 = 40 m
Pwmsclb = 10; // clock sb = 40/2*10 = 2 MHz (for motor supply)
Pwmscla = 5; // SA = clock a/2*5 = 5 m/10 = 500 k = sa used to control the steering gear
Pwmpol = 0xe2; // 1110_0010 Channel 7. Channel 6 and Channel 1. Channel 5 first outputs the high level and then outputs the low level. polx = 1 first outputs the high level and then outputs the low level; ppolx = 0 first output low level)
Pwmcae = 0x00; // left-aligned output (caex = 0 is left-aligned, and vice versa)

// Pwmclk = 0010_1010 (0 1 4 5-bit control sa_1; or a_0; 2 3 6 7-bit control SB_1 or B _0)
// Select the clock SA (500 kHz) for PWM channel 1 ),
// Select the clock SA (500 kHz) for the PWM channel 5 ),
// Select the clock Sb (10 MHz) for Channel 3)
// Select the clock B (40 MHz) for Channel 7)
// Select the clock B (40 MHz) for Channel 6)
Pwmclk = 0x2a; // 0010_1010

Pwmctl = 0x70; // 01100000000 con45 = 1, which is used together with Channel 4 and Channel 5. Con01 = 1. Use con23 = 1 in combination with Channel 0 and channel 1 to use Channel 3 and Channel 2.
Pwmper23 = 1000; // The channel period is 0.5 ms and the frequency is 2 kHz

Pwmdty23 = 0; // The duty cycle is 0%.

Pwmper01 = 10000; // one cycle is 50Hz = 500 kHz/10000
Pwmdty01 = upservocenter; // The duty cycle is 7.5%.

Pwmper45 = 10000; // one cycle is 50Hz = 500 kHz/10000
Pwmdty45 = 745; // The duty cycle is 7.5%.

Pwmper6 = 222; // the output frequency is 180 kHz = 40 m/222
Pwmdty6 = 67; // The duty cycle is 30%.
Pwmper7 = 222; // the output frequency is 180 kHz = 40 m/222
Pwmdty7 = 44; // The duty cycle is 20%.
Pwme = 0xea; // 1110_1010 enable Channels 1, 3, 7, 6, and 5 (the Enable of the combined channel is determined by Qualcomm channel)
}

/*************************************** ****************************
Gpio Initialization
1: output, 0: Input
Pb [0 .. 7] as the output port,

Pa [0 .. 7] as the output port
PM [0 .. 7] is used as the output port to control eight small LEDs (1 off, 0 on) on the core board)
PH [0 .. 3] as the input port
Added the use of port
**************************************** ****************************/
Void gpio_init (void)
{
Ddra | = 0xff; // port a serves as the output port
Ddrb | = 0xff; // port B serves as the output port
Ddrm | = 0xff; // M Port as the output port
Ddrh & = 0xf0; // The minimum four digits of pH are used as the input port.

Atd0dienl = 0xff;
Ddr1ad0 = 0x00; // use the pt1ad0 port as the input port

Porta = 0x00; // No signal is sent from the laser tube
Portb = 0x00; // No signal is sent from the laser tube
PTM = 0xff; // initialize to completely off (New Car Light)
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.